Android - TFLite OD - Невозможно скопировать в тензор TensorFlowLite (normalized_input_image_tensor) с 307200 байтами из буфера Java с 4320000 байтами - PullRequest
1 голос
/ 13 июля 2020

Я пытаюсь запустить свою собственную модель для обнаружения объектов. Я создал свой набор данных из облака Google - Vision (https://console.cloud.google.com/vision/) (я поместил изображения в рамку и пометил их), и он выглядит так:

enter image description here

After training the model, I downloaded the TFLite files (labelmap.txt, model.tflite and a json file) from here:

enter image description here

Then, I added them to the Android Object Detection example ( https://github.com/tensorflow/examples/tree/master/lite/examples/object_detection/android).

enter image description here

But when I run the project it crashes:

2020-07-12 18:03:05.160 14845-14883/? E/AndroidRuntime: FATAL EXCEPTION: inference
    Process: org.tensorflow.lite.examples.detection, PID: 14845
    java.lang.IllegalArgumentException: Cannot copy to a TensorFlowLite tensor (normalized_input_image_tensor) with 307200 bytes from a Java Buffer with 4320000 bytes.
        at org.tensorflow.lite.Tensor.throwIfSrcShapeIsIncompatible(Tensor.java:423)
        at org.tensorflow.lite.Tensor.setTo(Tensor.java:189)
        at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:154)
        at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:343)
        at org.tensorflow.lite.examples.detection.tflite.TFLiteObjectDetectionAPIModel.recognizeImage(TFLiteObjectDetectionAPIModel.java:197)
        at org.tensorflow.lite.examples.detection.DetectorActivity$2.run(DetectorActivity.java:182)
        at android.os.Handler.handleCallback(Handler.java:883)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:214)
        at android.os.HandlerThread.run(HandlerThread.java:67)

I tried changing the parameters TF_OD_API_IS_QUANTIZED to false and labelOffset to 0, and also I modified this line from the TFLiteObjectDetectionAPIModel.java to d.imgData = ByteBuffer.allocateDirect(_4_ * d.inputSize * d.inputSize * 3 * numBytesPerChannel); (I replaced 1 for 4)

I am new to this, I would really appreciate if someone could help me understand and resolve the error. Thank you!


Update: Here are the tflite files : https://drive.google.com/drive/folders/11QT8CgaYF2EseORgGCceh4DT80_pMiFM?usp=sharing (мне все равно, правильно ли модель распознает квадраты и круги, я просто хочу проверить, компилируется ли она на приложение android, а потом я его улучшу)

1 Ответ

4 голосов
/ 14 июля 2020

Существует превосходный инструмент визуализации, который называется Netron . Я использовал ваш файл .tflite, и ввод вашей модели:

введите описание изображения здесь

Итак, в вашем коде в строке, где вы вычисляете bytebuffer

1 * d.inputSize * d.inputSize * 3 * numBytesPerChannel

вы должны ввести

1 * 320 * 320 * 3 * 1

последняя «1» для uint8 .... если у вас были числа с плавающей запятой, вы должны поставить «4».

Удачного кодирования!

...