shaqian / flutter_tflite

Flutter plugin for TensorFlow Lite
https://pub.dartlang.org/packages/tflite
MIT License
632 stars 411 forks source link

Tensor and Java shapes mismatch super-issue #180

Open mgalgs opened 3 years ago

mgalgs commented 3 years ago

Cannot copy from a TensorFlowLite tensor (StatefulPartitionedCall:4) with shape X to a Java object with shape Y. seems to be a common problem (#176, #166, #162, #150, #147, #140, #109, #94, #84, #46, #41, #10).

Any guidance on resolving such shape mismatches?

Some additional validation with a more instructive error message might be helpful given the number of people having this problem.

E/AndroidRuntime(18313): FATAL EXCEPTION: AsyncTask #1
E/AndroidRuntime(18313): Process: com.mgalgs.routespotter, PID: 18313
E/AndroidRuntime(18313): java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime(18313):    at android.os.AsyncTask$4.done(AsyncTask.java:415)
E/AndroidRuntime(18313):    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
E/AndroidRuntime(18313):    at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
E/AndroidRuntime(18313):    at java.util.concurrent.FutureTask.run(FutureTask.java:271)
E/AndroidRuntime(18313):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:305)
E/AndroidRuntime(18313):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime(18313):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime(18313):    at java.lang.Thread.run(Thread.java:923)
E/AndroidRuntime(18313): Caused by: java.lang.IllegalArgumentException: Cannot copy from a TensorFlowLite tensor (StatefulPartitionedCall:4) with shape [1, 1] to a Java object with shape [1, 1, 4].
E/AndroidRuntime(18313):    at org.tensorflow.lite.Tensor.throwIfDstShapeIsIncompatible(Tensor.java:482)
E/AndroidRuntime(18313):    at org.tensorflow.lite.Tensor.copyTo(Tensor.java:252)
E/AndroidRuntime(18313):    at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:175)
E/AndroidRuntime(18313):    at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:360)
E/AndroidRuntime(18313):    at sq.flutter.tflite.TflitePlugin$RunSSDMobileNet.runTflite(TflitePlugin.java:671)
E/AndroidRuntime(18313):    at sq.flutter.tflite.TflitePlugin$TfliteTask.doInBackground(TflitePlugin.java:468)
E/AndroidRuntime(18313):    at sq.flutter.tflite.TflitePlugin$TfliteTask.doInBackground(TflitePlugin.java:442)
E/AndroidRuntime(18313):    at android.os.AsyncTask$3.call(AsyncTask.java:394)
E/AndroidRuntime(18313):    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/AndroidRuntime(18313):    ... 4 more
I/Process (18313): Sending signal. PID: 18313 SIG: 9
oezguensi commented 3 years ago

I am experiencing the same issue. @mgalgs Could you find any solution?

mgalgs commented 3 years ago

@oezguensi No, I ended up moving to https://github.com/am15h/tflite_flutter_plugin