Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to convert camera image to use for model using uint8 instead of float32 #42

Open
danielRi opened this issue Jun 3, 2024 · 0 comments

Comments

@danielRi
Copy link

danielRi commented Jun 3, 2024

Hi,

if I run the example app from flutter_vision, it works fine. However I replaced the yolov8n model with a pretrained model (it detects licens plates) and then I get the following exception:

E/flutter (19641): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(100, Detection Error, java.lang.IllegalArgumentException: Cannot copy to a TensorFlowLite tensor (normalized_input_image_tensor) with **270000** bytes from a Java Buffer with **1080000** bytes.
E/flutter (19641): 	at org.tensorflow.lite.TensorImpl.throwIfSrcShapeIsIncompatible(TensorImpl.java:416)
E/flutter (19641): 	at org.tensorflow.lite.TensorImpl.setTo(TensorImpl.java:140)
E/flutter (19641): 	at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:246)
E/flutter (19641): 	at org.tensorflow.lite.InterpreterImpl.runForMultipleInputsOutputs(InterpreterImpl.java:133)
E/flutter (19641): 	at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:80)
E/flutter (19641): 	at org.tensorflow.lite.InterpreterImpl.run(InterpreterImpl.java:126)
E/flutter (19641): 	at org.tensorflow.lite.Interpreter.run(Interpreter.java:80)
E/flutter (19641): 	at com.vladih.computer_vision.flutter_vision.models.Yolov8.detect_task(Yolov8.java:63)
E/flutter (19641): 	at com.vladih.computer_vision.flutter_vision.FlutterVisionPlugin$DetectionTask.run(FlutterVisionPlugin.java:273)
E/flutter (19641): 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:487)
E/flutter (19641): 	at java.util.concurrent.FutureTask.run(FutureTask.java:264)
E/flutter (19641): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
E/flutter (19641): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
E/flutter (19641): 	at java.lang.Thread.run(Thread.java:1012)
E/flutter (19641): , null)

If I investigate the model with Netron, I see the model expects the input in the format uint8, as opposed to model from the example, which expects float32. That would explain the factor 4 when comparing 270000 with 1080000 (see Exception above).

Input format from example:

Bildschirmfoto 2024-06-03 um 06 53 04

Input format from my pretrained license_plate model (which throws exception above)

Bildschirmfoto 2024-06-03 um 08 42 23

However I cant figure out how to convert the YUV420 Camera image from android to the expected byte buffer.

Can somebody help me, I know this is not an issue with the library, Im just basically begging for help because Im stuck.

Thanks a lot,
Daniel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant