android-demo-app
android-demo-app copied to clipboard
An android app with a custom model of object detection runs failed
I'm working on an object detection project using yolov5 model and custom datasets. I followed this tutorial. https://github.com/pytorch/android-demo-app/tree/master/ObjectDetection
I modified the export.py
in the yolov5 https://github.com/ultralytics/yolov5/blob/master/export.py following the tutorial.
I moved the
best.torchscript.ptl
file to the Android assets
folder and modified MainActivity.java
.
But an error was occured that "Lite Interpreter version number does not match. The model version must be between 3 and 7 but the model version is 8 ()". I saw a solution https://github.com/pytorch/android-demo-app/issues/202 and tried the torch.jit.mobile which has a _backport_for_mobile function to "backport" a model to a given version
I used the file best_v5.torchscript.ptl
obtained by the above function, but the Android app does not run. The build and launch were successful, but an error occurs with the following screen in the emulator. How can I fix this error?
FATAL EXCEPTION: main
Process: org.pytorch.demo.objectdetection, PID: 10077
java.lang.RuntimeException: Unable to start activity ComponentInfo{org.pytorch.demo.objectdetection/org.pytorch.demo.objectdetection.MainActivity}: com.facebook.jni.CppException: isTuple()INTERNAL ASSERT FAILED at "../aten/src/ATen/core/ivalue_inl.h":1396, please report a bug to PyTorch. Expected Tuple but got String ()
Exception raised from toTuple at ../aten/src/ATen/core/ivalue_inl.h:1396 (most recent call first):
FYI the app runs successfully with the model file yolov5s.torchscript.ptl
in the tutorial.
Similar problem here. i didn't back-port my custom model, instead. I updated torchvision lite to 1.12 and I still got this in the app debug logs:
E/AndroidRuntime: FATAL EXCEPTION: main Process: org.pytorch.demo.objectdetection, PID: 13240 java.lang.RuntimeException: Unable to start activity ComponentInfo{org.pytorch.demo.objectdetection/org.pytorch.demo.objectdetection.MainActivity}: com.facebook.jni.CppException: isTuple()INTERNAL ASSERT FAILED at "../aten/src/ATen/core/ivalue_inl.h":1908, please report a bug to PyTorch. Expected Tuple but got String () Exception raised from toTuple at ../aten/src/ATen/core/ivalue_inl.h:1908
Will try to back-port model to version 5 and test it with torchvision lite version 1.10
Yup. Same problem here even after backport. Caused by: com.facebook.jni.CppException: isTuple()INTERNAL ASSERT FAILED at "../aten/src/ATen/core/ivalue_inl.h":1396, please report a bug to PyTorch. Expected Tuple but got String () Exception raised from toTuple at ../aten/src/ATen/core/ivalue_inl.h:1396
Please, help is needed.
I also encountered this issue, I can't get idea about resolving. I'm working on an object detection project using yolov5 model and custom datasets. I followed this tutorial. https://github.com/pytorch/android-demo-app/tree/master/ObjectDetection
I modified the export.py in the yolov5 https://github.com/ultralytics/yolov5/blob/master/export.py following the tutorial.
Please response here ... Anyone assist me, we need your help.
Advanced Thanks Lots' ...
I fixed it eventually by changing the input tensor shape to match the one of my model. It should work with torchlite 1.12 iirc.
If you forgot to check on your input and output tensor shapes in the app code then perhaps you should check again, hope it works for you. Albeit it's going to be slow, I'm still working on figuring out a workaround for that detection delay.
Here's something I tried: Check around line 39 in Prepostprocessor class. The column value for input tensor could be different from the one in your model. Try changing it to a suitable one, I remember that was one of the problems related to this error. and a few tweaks in Prepostprocessor class and changing to a proper version of torchlite in gradle build script sloved it. I'll post more details on how I fixed it once I'm on my computer.
This app still works. so It's not an actual issue with the code, it's just outdated torchlite and input mismatch irrc. Hope this helps 🙏 Please update the issue if it does.
Hi, Great thanks for your response. Sorry I am fresh for this ( Pytorch, Tensorflow, etc) I didn't get your exact point. How do checks input & output tensor shapes for my app code, models? if you don't mind, please assist me from scratch in Object Detection Pytorch App. if you wish, you are feel free to contact and teach me for better communication use this mail : [email protected]
I try to catch input and output tensor shapes in my understading ,given below then I did changes in prepostprocessor.java
But till get same issue
please anyone help for resolve this issue ...
Thankyou @Absentation, You are answer helped to resolve my issue. I fix this issue, just I upadate on " implementation 'org.pytorch:pytorch_android_lite:1.12.1' implementation 'org.pytorch:pytorch_android_torchvision_lite:1.10.0' in my build.gradle file. it's work for me . It will helps for others.
Thankyou :-)
Hey, @aravinthk00. Did you train yolo last version? I have the same problem and outputs, but org.pytorch:pytorch_android_lite:1.12.1 didn't solve problem.
Hey, @aravinthk00. Did you train yolo last version? I have the same problem and outputs, but org.pytorch:pytorch_android_lite:1.12.1 didn't solve problem.
@AnnaKholkina did you check if your model input and output sizes match the values in the app code?
Yes, I did. @Absentation
I also have bad predictions. On PC model results with thresholds like 0.9+, in the Android-app I have same predictions with 0.3-0.4. Maybe, if you have a good Android-model, can you help me with correct export?
please try this comment " ### python train.py --batch 32 --cfg yolov5m6.yaml --weights '' --data coco.yaml --img 1280 --epochs 300 " to train the your model then export the model pt to ptl after import the model in your app source code and increase your threshold value also. I think it will be helpful for you . Thankyou :-)
Changing:
implementation 'org.pytorch:pytorch_android_lite:1.10.1
to:
implementation 'org.pytorch:pytorch_android_lite:1.12.1
in
build.gradle
didn't solve it for me either...
the version (implementation 'org.pytorch:pytorch_android_lite:1.12.1) not supporting in my android studio
the version (implementation 'org.pytorch:pytorch_android_lite:1.12.1) not supporting in my android studio
Clean gradle and Rebuild gradle
the version (implementation 'org.pytorch:pytorch_android_lite:1.12.1) not supporting in my android studio
Clean gradle and Rebuild gradle
i have rebuild it still my app is not running