Работает ли этот код для передачи модели tflite в кадр прямой камеры? [закрыто]JAVA

Программисты JAVA общаются здесь
Anonymous
Работает ли этот код для передачи модели tflite в кадр прямой камеры? [закрыто]

Сообщение Anonymous »


I implemented a small app with Android studio. the app has access to a camera. Afterwards i trained model with a pretrained dataset(yoloV5) in google Collab. Then i changed the pytorch model to in Tensorflow lite modell.

I used the following link for the Implementation:

https://heartbeat.comet.ml/adding-a-ten ... c2c6232257

https://hamzaasif-mobileml.medium.com/g ... cf4437f5fd

Know i want to use the app but the camera does not detect anything.

For the Training (11 epoch, 16 batch, 9500 images).

private void processImage() { imageConverter.run(); rgbFrameBitmap = Bitmap.createBitmap(previewWidth, previewHeight, Bitmap.Config.ARGB_8888); rgbFrameBitmap.setPixels(rgbBytes, 0, previewWidth, 0, 0, previewWidth, previewHeight); // Load the TFLite model Interpreter tflite = new Interpreter(Objects.requireNonNull(loadModelFile("best-fp16.tflite"))); // Preprocess the input image Bitmap resizedBitmap = Bitmap.createScaledBitmap(rgbFrameBitmap, 416, 416, true); ByteBuffer inputBuffer = convertBitmapToByteBuffer(resizedBitmap); // Define the outputBuffer float[] outputArray = new float[1]; FloatBuffer outputBuffer = FloatBuffer.wrap(outputArray); // Run model inference tflite.run(inputBuffer, outputBuffer); // You need to define outputBuffer for (float score : outputArray) { Toast.makeText(this,"Detect", Toast.LENGTH_LONG).show(); } tflite.close(); postInferenceCallback.run(); } private ByteBuffer convertBitmapToByteBuffer(Bitmap bitmap) { int byteSize = bitmap.getRowBytes() * bitmap.getHeight() * 4; // Assuming ARGB_8888 ByteBuffer byteBuffer = ByteBuffer.allocateDirect(byteSize); byteBuffer.order(ByteOrder.nativeOrder()); bitmap.copyPixelsToBuffer(byteBuffer); System.out.println(byteBuffer); return byteBuffer; } protected void fillBytes(final Image.Plane[] planes, final byte[][] yuvBytes) { // Because of the variable row stride it's not possible to know in // advance the actual necessary dimensions of the yuv planes. for (int i = 0; i < planes.length; ++i) { final ByteBuffer buffer = planes.getBuffer(); if (yuvBytes == null) { yuvBytes = new byte[buffer.capacity()]; } buffer.get(yuvBytes); System.out.println(yuvBytes); } } private MappedByteBuffer loadModelFile(String tflite) { try { AssetFileDescriptor fileDescriptor = this.getAssets().openFd("best-fp16.tflite"); FileInputStream inputStream = new FileInputStream(fileDescriptor.getFileDescriptor()); FileChannel fileChannel = inputStream.getChannel(); long startOffset = fileDescriptor.getStartOffset(); long declaredLength = fileDescriptor.getDeclaredLength(); return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength); } catch (IOException e) { e.printStackTrace(); return null; } } Can someone help me?


Источник: https://stackoverflow.com/questions/780 ... ive-camera

Вернуться в «JAVA»