pytorch / android-demo-app

PyTorch android examples of usage in applications
1.46k stars 604 forks source link

Problems of Object Detection,APP crash #228

Closed tangning9495 closed 2 years ago

tangning9495 commented 2 years ago

I run the object detection demo. Package the apk and install apk on device, but it always crashed where I run it on Android VM or a real phone. Anybody can help me? It's my first time to develop android app.

cloveropen commented 2 years ago

maybe the scores length and the label length are not equal

tangning9495 commented 2 years ago

maybe the scores length and the label length are not equal

I try to debug the apk and get the bug info: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.pytorch.demo.objectdetection/org.pytorch.demo.objectdetection.MainActivity}: com.facebook.jni.CppException: PytorchStreamReader failed locating file bytecode.pkl: file not found ()

but I can't find the real problem. You mean that the results is defferent from the length of classes in classes.txt file? I rewrite the new classes file, also use the original yolov5s.pt and original txt file, it always crash when I run the apk.

FlamingJay commented 2 years ago

maybe the scores length and the label length are not equal

I try to debug the apk and get the bug info: java.lang.RuntimeException: Unable to start activity ComponentInfo{org.pytorch.demo.objectdetection/org.pytorch.demo.objectdetection.MainActivity}: com.facebook.jni.CppException: PytorchStreamReader failed locating file bytecode.pkl: file not found ()

but I can't find the real problem. You mean that the results is defferent from the length of classes in classes.txt file? I rewrite the new classes file, also use the original yolov5s.pt and original txt file, it always crash when I run the apk.

hey, i met this issue also. i solved it in following ways:

  1. generate yolov5s.torchscript.ptl using the origion repo
  2. use the cmd: python3 export.py --weights=yolov5s.pt --include=torchscript --optimize or python export.py --weights=yolov5s.pt --include=torchscript --optimize from the export.py, we can know it uses the 'save' func but not the '_save_for_lite_interpreter' func.use the correct version of android plugins
  3. pytorch_android_lite and pytorch_android_torchvision_lite which corresponding to your pytorch which generates ptl file