Im trying to use a custom trained Yolo5 model which Ive then converted to ONNX to use with OpenCV.
The error Im getting is outputs = net.forward(net.getUnconnectedOutLayersNames())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cv2.error: OpenCV(4.6.0) ./modules/dnn/include/opencv2/dnn/shape_utils.hpp:170: error: (-215:Assertion failed) start <= (int)shape.size() && end <= (int)shape.size() && start <= end in function ‘total’
After googling I can find several people with similar issue which suggests its caused by the conversion but none of those posts have a solution.
I did the conversion like this: python.exe .\export.py --weights c:\Users\Andrew\best.pt --include onnx
And the output from that indicated all went OK:
(.venv) PS C:\Users\Andrew\PycharmProjects\Yolo5Trainer\yolov5> python.exe .\export.py --weights c:\Users\Andrew\best.pt --include onnx --simplify
export: data=C:\Users\Andrew\PycharmProjects\Yolo5Trainer\yolov5\data\coco128.yaml, weights=[‘c:\Users\Andrew\best.pt’], imgsz=[640, 640], batch_size=1, device=cpu, half=False, inplace=False, keras=False, optimize=False, int8
=False, per_tensor=False, dynamic=False, cache=, simplify=True, mlmodel=False, opset=17, verbose=False, workspace=4, nms=False, agnostic_nms=False, topk_per_class=100, topk_all=100, iou_thres=0.45, conf_thres=0.25, include=[‘onnx’]
YOLOv5 v7.0-430-g459d8bf0 Python-3.12.4 torch-2.8.0+cpu CPU
Fusing layers…
Model summary: 157 layers, 1768636 parameters, 0 gradients, 4.2 GFLOPs
PyTorch: starting from c:\Users\Andrew\best.pt with output shape (1, 25200, 12) (3.7 MB)#
ONNX: starting export with onnx 1.19.0…
ONNX: slimming with onnxslim 0.1.68…
ONNX: export success 15.0s, saved as c:\Users\Andrew\best.onnx (7.2 MB)
Export complete (15.4s)
Results saved to C:\Users\Andrew
Detect: python detect.py --weights c:\Users\Andrew\best.onnx
Validate: python val.py --weights c:\Users\Andrew\best.onnx
PyTorch Hub: model = torch.hub.load(‘ultralytics/yolov5’, ‘custom’, ‘c:\Users\Andrew\best.onnx’)
Visualize: https://netron.app
Im using OpenCV 4.6 on Raspberry Pi OS 12
Is anyone able to give me pointers as to how I can debug this further please?