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 (serving_default_input_1:0) with 1769472 bytes from a Java Buffer with 1732800 bytes. #6912

Closed
1 of 2 tasks
VYRION-Ai opened this issue Mar 9, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@VYRION-Ai
Copy link

Search before asking

  • I have searched the YOLOv5 issues and found no similar bug report.

YOLOv5 Component

No response

Bug

I'm coding yolov5 tflite on android studio, the code is working fine on previous version on yolov5 (befor v6). Now when I use the new trend network and convert it to tflite I get this error
i export with this
python export.py --weights best_n.pt --include tflite --img 380

ava.lang.IllegalArgumentException: Cannot copy to a TensorFlowLite tensor (serving_default_input_1:0) with 1769472 bytes from a Java Buffer with 1732800 bytes.
        at org.tensorflow.lite.Tensor.throwIfSrcShapeIsIncompatible(Tensor.java:447)
        at org.tensorflow.lite.Tensor.setTo(Tensor.java:189)
        at org.tensorflow.lite.NativeInterpreterWrapper.run(NativeInterpreterWrapper.java:200)
        at org.tensorflow.lite.Interpreter.runForMultipleInputsOutputs(Interpreter.java:374)
        at com.android.animal_cam_alert.tflite.YoloV5Classifier.recognizeImage(YoloV5Classifier.java:392)
        at com.android.animal_cam_alert.DetectorActivity$2.run(DetectorActivity.java:254)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)

Environment

No response

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@VYRION-Ai VYRION-Ai added the bug Something isn't working label Mar 9, 2022
@VYRION-Ai
Copy link
Author

VYRION-Ai commented Mar 9, 2022

sorry i got the errro
when i export the tflite with img size 380 , it is acutly exported as 384

i got the solution from this link
https://discuss.tensorflow.org/t/custom-transfer-learning-tensorflowlite-model-gives-error-in-android-code-for-image-classification/1010/6

https://netron.app/

@glenn-jocher
Copy link
Member

@totoadel TFLite export works correctly, I'm unable to reproduce any issues using your command:
Screenshot 2022-03-09 at 11 13 43

@VYRION-Ai
Copy link
Author

@totoadel TFLite export works correctly, I'm unable to reproduce any issues using your command: Screenshot 2022-03-09 at 11 13 43

I am sorry it works well, the problem was with the image size , in export command enter the img size as 380 but the exported size is 384, i check it with from the site netron.app

@glenn-jocher
Copy link
Member

@totoadel YOLOv5 input shapes must meet constraints of 32 pixel multiples for P5 models like YOLOv5s and 64 multiples for P6 models like YOLOv5s6.

@Siddharth1698
Copy link

@totoadel YOLOv5 input shapes must meet constraints of 32 pixel multiples for P5 models like YOLOv5s and 64 multiples for P6 models like YOLOv5s6.

This actually solves the issue. When training the model, its best to train with image size which is divisible by 32 and 64. The app kept crashing but then I noticed the image size not divisible by 32 and 64. Retrained it and now it isn't crashing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants