0
votes

Main Error is

Cannot convert between a TensorFlowLite tensor with type UINT8 and a Java object of type [[F (which is compatible with the TensorFlowLite type FLOAT32).

Model used from https://www.tensorflow.org/lite/models/image_classification/overview

Model load code

      String res = await Tflite.loadModel(
        model: "assets/mobilenet_v1.tflite",
        labels: "assets/mobilenet_v1.txt",
        numThreads: 1, // defaults to 1
        isAsset: true,
        useGpuDelegate:
            false, // defaults to false, set to true to use GPU delegate
      );

Running model on image

    var recognitions = await Tflite.runModelOnImage(
      path: image.path,
      imageMean: 0.0,
      imageStd: 255.0, // defaults to 1.0
      threshold: 0.2, // defaults to 0.1
    );

    setState(() {
      _recognitions = recognitions;
      print('Got ${_recognitions.length} recognitions');
    });

Error stack

I/flutter (14229): Working on /data/user/0/com.example.safety_app/cache/image_picker2866004901851985262.jpg
W/com.example.safety_app(14229): type=1400 audit(0.0:118930): avc: denied { read } for comm=4173796E635461736B202332 name="u:object_r:vendor_default_prop:s0" dev="tmpfs" ino=18666 scontext=u:r:untrusted_app:s0:c170,c258,c512,c768 tcontext=u:object_r:vendor_default_prop:s0 tclass=file permissive=0
E/libc    (14229): Access denied finding property "ro.hardware.chipname"
E/AndroidRuntime(14229): FATAL EXCEPTION: AsyncTask #2
E/AndroidRuntime(14229): Process: com.example.safety_app, PID: 14229
E/AndroidRuntime(14229): java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime(14229):    at android.os.AsyncTask$3.done(AsyncTask.java:354)
E/AndroidRuntime(14229):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
E/AndroidRuntime(14229):    at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
E/AndroidRuntime(14229):    at java.util.concurrent.FutureTask.run(FutureTask.java:271)
E/AndroidRuntime(14229):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
E/AndroidRuntime(14229):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime(14229):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime(14229):    at java.lang.Thread.run(Thread.java:764)
E/AndroidRuntime(14229): Caused by: java.lang.IllegalArgumentException: Cannot convert between a TensorFlowLite tensor with type UINT8 and a Java object of type [[F (which is compatible with the TensorFlowLite type FLOAT32).
E/AndroidRuntime(14229):    at org.tensorflow.lite.Tensor.throwIfTypeIsIncompatible(Tensor.java:406)
E/AndroidRuntime(14229):    at org.tensorflow.lite.Tensor.copyTo(Tensor.java:251)
E/AndroidRuntime(14229):    at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:170)
E/AndroidRuntime(14229):    at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:343)
E/AndroidRuntime(14229):    at org.tensorflow.lite.Interpreter.run(Interpreter.java:304)
E/AndroidRuntime(14229):    at sq.flutter.tflite.TflitePlugin$RunModelOnImage.runTflite(TflitePlugin.java:481)
E/AndroidRuntime(14229):    at sq.flutter.tflite.TflitePlugin$TfliteTask.doInBackground(TflitePlugin.java:448)
E/AndroidRuntime(14229):    at sq.flutter.tflite.TflitePlugin$TfliteTask.doInBackground(TflitePlugin.java:422)
E/AndroidRuntime(14229):    at android.os.AsyncTask$2.call(AsyncTask.java:333)
E/AndroidRuntime(14229):    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/AndroidRuntime(14229):    ... 4 more
W/System  (14229): A resource failed to call close.
I/Process (14229): Sending signal. PID: 14229 SIG: 9
Lost connection to device.
Exited (sigterm)

1

1 Answers

1
votes

Let me start with something obvious: you are trying to feed floating point image to integer-type model input.

According to your link there is only 1 model: Mobilenet_V1_1.0_224_quant. This is quantized which performs all operations in integer numbers and requires integer on input:

All of the models require three color channels per pixel (red, green, and blue). Quantized models require 1 byte per channel, and float models require 4 bytes per channel.

If described above is real case I see few solutions here:

  1. Use the same model, manage correctly your input. Quantized models performs better on CPU but have lower accuracy
  2. Check in detail hosted models and pick floating point one