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

Cannot copy to a TensorFlowLite tensor (conv2d_input) with 16384 bytes from a Java Buffer with 49152 bytes. #2

Open
priyanshnama opened this issue Sep 24, 2020 · 4 comments
Labels
bug Something isn't working good first issue Good for newcomers Hacktoberfest Good for Participants of Hacktoberfest help wanted Extra attention is needed

Comments

@priyanshnama
Copy link
Member

Describe the bug
Input size mismatch between tflite model and java buffer.

To Reproduce
Steps to reproduce the behavior:

  1. Click on drop down.
  2. Choose "Identify Number"
  3. click on "Choose Image"
    4.Choose and image and click Predict.
  4. the app crashes at this point with error same as title the error log is attached below.
2020-09-24 22:15:36.828 19961-19961/com.priyanshnama.tf_droid E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.priyanshnama.tf_droid, PID: 19961
    java.lang.IllegalStateException: Could not execute method for android:onClick
        at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:414)
        at android.view.View.performClick(View.java:6312)
        at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:992)
        at android.view.View$PerformClick.run(View.java:24943)
        at android.os.Handler.handleCallback(Handler.java:790)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:192)
        at android.app.ActivityThread.main(ActivityThread.java:6754)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:828)
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409)
        at android.view.View.performClick(View.java:6312at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:992at android.view.View$PerformClick.run(View.java:24943at android.os.Handler.handleCallback(Handler.java:790at android.os.Handler.dispatchMessage(Handler.java:99at android.os.Looper.loop(Looper.java:192at android.app.ActivityThread.main(ActivityThread.java:6754at java.lang.reflect.Method.invoke(Native Methodat com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:828Caused by: java.lang.IllegalArgumentException: Cannot copy to a TensorFlowLite tensor (conv2d_input) with 16384 bytes from a Java Buffer with 49152 bytes.
        at org.tensorflow.lite.Tensor.throwIfSrcShapeIsIncompatible(Tensor.java:444)
        at org.tensorflow.lite.Tensor.setTo(Tensor.java:189)
        at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:159)
        at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:360)
        at org.tensorflow.lite.Interpreter.run(Interpreter.java:319)
        at com.priyanshnama.tf_droid.Classifier.recognizeImage(Classifier.kt:66)
        at com.priyanshnama.tf_droid.MainActivity.predict(MainActivity.kt:74)
        at java.lang.reflect.Method.invoke(Native Methodat androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:409at android.view.View.performClick(View.java:6312at com.google.android.material.button.MaterialButton.performClick(MaterialButton.java:992at android.view.View$PerformClick.run(View.java:24943at android.os.Handler.handleCallback(Handler.java:790at android.os.Handler.dispatchMessage(Handler.java:99at android.os.Looper.loop(Looper.java:192at android.app.ActivityThread.main(ActivityThread.java:6754at java.lang.reflect.Method.invoke(Native Methodat com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:549at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:828

Expected behavior
The app should predict the number shown by fingers and output the same to user as a toast.

Additional context
try to manage size of image in MainActivity file.

@priyanshnama priyanshnama added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed Hacktoberfest Good for Participants of Hacktoberfest labels Sep 24, 2020
@shivamsouravjha
Copy link
Member

@heythere12 our project is stuck here, could you help?

@heythere12
Copy link

@shivamsouravjha I'll surely have a look and get back to you.

Thanks
Nishi

priyanshnama added a commit that referenced this issue Oct 6, 2020
https:// links updated as ownership was transferred
@priyanshnama
Copy link
Member Author

@heythere12 Models files are added. you can have a look at them.

Possible Solution
Try to add a bunch of code in model file which shall convert the image (of any given size) to size (64 X 64) Required by the Project.

@shivamsouravjha
Copy link
Member

@priyanshnama I've told you many times this is not how it's done 🤦‍♂️tflite download the already made up structure of model it can't config shape changed.

Model is made on shape of a dataset and can't be tempered as well,to my best knowledge it is work for Android part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers Hacktoberfest Good for Participants of Hacktoberfest help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants