I have custom model trained on yolov5s v5 and I converted it to torchscript.ptl using ultralytics export.py with code modification as told here.
When I build on android i get the following error:
error that appears in debugging:
E/AndroidRuntime: FATAL EXCEPTION: Thread-2
Process: org.pytorch.demo.objectdetection, PID: 27891
java.lang.ArrayIndexOutOfBoundsException: length=1310400; index=1310449
I changed my torch version also, I am still facing the same issue.
yolov5s.torchscript.ptl model file provided in the repo. works fine. I’m facing this issue when I use my custom model.
Thank you for your reply. I changed the value as calculated by 25200*(num_of_class+5) but I’m still facing the same issue.
Do I need to change this value also or any other ?
“private static int mOutputColumn = 85; // left, top, right, bottom, score and 80 class probability”
I changed only " private static int mOutputRow = 25200; // as decided by the YOLOv5 model for input image of size 640*640" this value.
I even changed mOutputColumn = 85 to my custom class number and class number + 5 also but I am still facing the same issue.
So I solved this issue.
You need to change only mOutputColumn value with you number of classes+5. I was changing mOutputRow = 25200 with value calculated by 25200*(num_of_class+5) which caused this issue.
// model output is of size 25200*(num_of_class+5)
private static int mOutputRow = 25200; // as decided by the YOLOv5 model for input image of size 640*640
private static int mOutputColumn = 52; // left, top, right, bottom, score and 80 class probability
private static float mThreshold = 0.50f; // score above which a detection is generated