ultralytics / yolov5

YOLOv5 🚀 in PyTorch > ONNX > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
49.65k stars 16.1k forks source link

Question about Android Deploymeny #1847

Closed lujiazho closed 3 years ago

lujiazho commented 3 years ago

❔Question

does anybody why would this problem come out? when I detect the image with the int8 tflite model by detect.py, it looks like this image image

it can detect every wheat head correctly without any wrong box

But when I deploy the same model file on Android, it looks like this all the time, how could that be ? image image

does anybody have the same problem?

Additional context

I used the way of zldrobit, and the link is https://github.com/zldrobit/yolov5/tree/tf-android

glenn-jocher commented 3 years ago

@leaving-voider can you show results on the same image? There's really no point in showing model A on image 1 vs model B on image 2.

lujiazho commented 3 years ago

@leaving-voider can you show results on the same image? There's really no point in showing model A on image 1 vs model B on image 2.

thanks for reply, actually they are the same model. And the model deployed on Android cannot have any meanful detection, no matter what image I put it on/(ㄒoㄒ)/

jeenhyung commented 3 years ago

@leaving-voider Hi, I faced the same essue. And I solved.

If you used tf.py for convert .pt to .tflite, You just need to modify all source code from numClasss+5 to numClass.

Example, float[][][] out = new float[1][output_box][numClass + 5]; to float[][][] out = new float[1][output_box][numClass];

Because, You have already calculated it when you convert tflite.

Good luck!

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

zldrobit commented 3 years ago

@jeenhyung Thanks for pointing out the problem. I forgot to subtract 5 (xywh and confidence of bounding boxes) from the last dimension of the output-tensor shape.

This problem is fixed by changing: https://github.com/zldrobit/yolov5/commit/021345e4d4ed5484c9ed7525b4c447e8f40c0129#diff-a26b4f7400b6abfb58aa58de11ddb26a87e70312b2df009ca7d9043d405dfeb2L134-R134 in the new tf-android branch.

github-actions[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.