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

Using an own model #15

Closed
bvlbvl opened this issue Oct 16, 2019 · 1 comment
Closed

Using an own model #15

bvlbvl opened this issue Oct 16, 2019 · 1 comment

Comments

@bvlbvl
Copy link

bvlbvl commented Oct 16, 2019

Hi,

I'm trying to integrate an own model based on mobileNetV2 with the image size 224. The base is the google example

'https://colab.research.google.com/github/tensorflow/examples/blob/master/community/en/flowers_tf_lite.ipynb'

As mobileNet with the same image size is used also for "MobileNet", I reused the button and only changed the path to the custom assets in loadModel():

 default:
/*        res = await Tflite.loadModel(
            model: "assets/ssd_mobilenet.tflite",
            labels: "assets/ssd_mobilenet.txt");*/

        res = await Tflite.loadModel(
            model: "assets/model_flowers.tflite",
            labels: "assets/labels_flowers.txt");

unfotunately it doesn't work:


E/AndroidRuntime(28217): FATAL EXCEPTION: AsyncTask #2
E/AndroidRuntime(28217): Process: com.example.examplerealtime, PID: 28217
E/AndroidRuntime(28217): java.lang.RuntimeException: An error occurred while executing doInBackground()
E/AndroidRuntime(28217): 	at android.os.AsyncTask$3.done(AsyncTask.java:354)
E/AndroidRuntime(28217): 	at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383)
E/AndroidRuntime(28217): 	at java.util.concurrent.FutureTask.setException(FutureTask.java:252)
E/AndroidRuntime(28217): 	at java.util.concurrent.FutureTask.run(FutureTask.java:271)
E/AndroidRuntime(28217): 	at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245)
E/AndroidRuntime(28217): 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
E/AndroidRuntime(28217): 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
E/AndroidRuntime(28217): 	at java.lang.Thread.run(Thread.java:764)
E/AndroidRuntime(28217): Caused by: java.lang.IllegalArgumentException: Cannot copy between a TensorFlowLite tensor with shape [1, 5] and a Java object with shape [1, 5, 4].
E/AndroidRuntime(28217): 	at org.tensorflow.lite.Tensor.throwIfShapeIsIncompatible(Tensor.java:291)
E/AndroidRuntime(28217): 	at org.tensorflow.lite.Tensor.throwIfDataIsIncompatible(Tensor.java:258)
E/AndroidRuntime(28217): 	at org.tensorflow.lite.Tensor.copyTo(Tensor.java:150)
E/AndroidRuntime(28217): 	at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:183)
E/AndroidRuntime(28217): 	at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:275)
E/AndroidRuntime(28217): 	at sq.flutter.tflite.TflitePlugin$RunSSDMobileNet.runTflite(TflitePlugin.java:622)
E/AndroidRuntime(28217): 	at sq.flutter.tflite.TflitePlugin$TfliteTask.doInBackground(TflitePlugin.java:419)
E/AndroidRuntime(28217): 	at sq.flutter.tflite.TflitePlugin$TfliteTask.doInBackground(TflitePlugin.java:393)
E/AndroidRuntime(28217): 	at android.os.AsyncTask$2.call(AsyncTask.java:333)
E/AndroidRuntime(28217): 	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
E/AndroidRuntime(28217): 	... 4 more

As far I understand it correctly, the tensor shape passed to the model doesn't correspond to the required tensor shape :
Cannot copy between a TensorFlowLite tensor with shape [1, 5] and a Java object with shape [1, 5, 4]

Unfortunately I am not able to debug sq.flutter.tflite.TflitePlugin.java

What is the correct way to integrate a custom model?

Thank you!

@bvlbvl
Copy link
Author

bvlbvl commented Oct 17, 2019

solved it:
it should be placed under mobilenet and not ssdmoblienet

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