Error in Incompatibility between the ONNX model format and the OpenCV DNN module
Pretty much what the title stated. I am having error when running the code. This is the exact error:
[ERROR:[email protected]] global ./modules/dnn/src/onnx/onnx_importer.cpp (1018) handleNode DNN/ONNX: ERROR during processing node with 2 inputs and 1 outputs: [Reshape]:(onnx_node!/model.22/dfl/Reshape) from domain='ai.onnx'
thread 'main' panicked at src/main.rs:20:161:
called `Result::unwrap()` on an `Err` value: Error { code: "StsError, -2", message: "OpenCV(4.6.0) ./modules/dnn/src/onnx/onnx_importer.cpp:1040: error: (-2:Unspecified error) in function 'handleNode'\n> Node [[email protected]]:(onnx_node!/model.22/dfl/Reshape) parse error: OpenCV(4.6.0) ./modules/dnn/src/layers/reshape_layer.cpp:108: error: (-215:Assertion failed) total(srcShape, srcRange.start, srcRange.end) == maskTotal in function 'computeShapeByReshapeMask'\n> " }
I used the opencv = 0.91.3 which is the dependency of od_opencv. I am having issue if I used the latest version of opencv so I decided to use the version that it depends.
What version of OpenCV do you have installed? upd: I see, 4.6.0
Also, what kind of opset do you have in your weights? Asking because it is confirmed that only opset=12 is working, see the ref: https://github.com/opencv/opencv/issues/23365
Fastest way to get opset=12 for YOLOv8:
python3 -c 'from ultralytics import YOLO; model = YOLO("pretrained/yolov8n.pt"); model.export(format="onnx", opset=12)'
From crates, I used opencv = "0.91.3". The version I have on my device is 4.6.0. I cannot use the opencv = "0.95.3" from crates as it will have issue on versioning. Since od_opencv already includes the 0.91.3, the rust analyzer I think is having problem which version it will use.
Quick update, I tried to set the opset of my weigths to 12. And this is the error message that I have now:
thread 'main' panicked at src/main.rs:36:77:
called `Result::unwrap()` on an `Err` value: Error { code: "StsAssert, -215", message: "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'\n" }
Which I think has something to do with the shape of the tensor or array not meeting the expected value during processing.
Quick update, I tried to set the
opsetof my weigths to 12. And this is the error message that I have now:thread 'main' panicked at src/main.rs:36:77: called `Result::unwrap()` on an `Err` value: Error { code: "StsAssert, -215", message: "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'\n" }Which I think has something to do with the shape of the tensor or array not meeting the expected value during processing.
Are your weights are custom or pretrained (by Ultralytics)? I've only tested second on my setup... I can try to reproduce error in OpenCV 4.8+ version if you can share the weights.
Closed due inactivity