Open Neo-Abhishek opened 1 year ago
Another interesting observation: The above error occurs when exporting the model for dynamic batch input using this syntax -
torch.onnx.export(model.visual,
image_input,
"clip-visual.onnx",
export_params=True,
opset_version=14,
do_constant_folding=True,
input_names = ['input'],
output_names = ['output'],
dynamic_axes={'input' : {0 : 'batch_size'}, 'output' : {0 : 'batch_size'}})
but when exporting for single image input by making the 'dynamic_axes' parameter above empty cv2.dnn.readNet() is successful in reading the onnx model
dynamic_axes = {}
but this time the model output dimension is wrong - [50,512] whereas it should be [1,512].
@Neo-Abhishek Thanks for your reporting. ConstantOfShape
doesn't support batch_size
until OpenCV 5.0 released. I think you can set batch_size to 1 then use single image input model.
but this time the model output dimension is wrong - [50,512] whereas it should be [1,512].
@WanliZhong I have already tried that and the dnn.readNet() is a success with single image input but the model output is incorrect as mentioned above. Of all the 50 vectors only the first index vector is the correct output and remaining are not useful.
but this time the model output dimension is wrong - [50,512] whereas it should be [1,512].
@WanliZhong I have already tried that and the dnn.readNet() is a success with single image input but the model output is incorrect as mentioned above. Of all the 50 vectors only the first index vector is the correct output and remaining are not useful.
Could you put this model on this issue?
but this time the model output dimension is wrong - [50,512] whereas it should be [1,512].
@WanliZhong I have already tried that and the dnn.readNet() is a success with single image input but the model output is incorrect as mentioned above. Of all the 50 vectors only the first index vector is the correct output and remaining are not useful.
Could you put this model on this issue?
Model with single image input - https://drive.google.com/file/d/1DSA-0GWEA7WuCyCIO_LK_3cfaqTSgj-q/view?usp=share_link
I faced the same problem, trying to run this project: https://github.com/hpc203/YOLOP-opencv-dnn, which is based on https://github.com/hustvl/YOLOP
can you try to add --opset 12 https://forum.opencv.org/t/error-when-reading-yolo5-as-onnx-using-cv2/11507/3
Model run to python.
cv2.dnn.readNetFromONNX(model_yaw)
Same problem to c++ language.
cv::dnn::readNetFromONNX(model_yaw)
Please help
[ERROR:0] global ./modules/dnn/src/onnx/onnx_importer.cpp (718) handleNode DNN/ONNX: ERROR during processing node with 2 inputs and 1 outputs: [Squeeze]:(model/block1a_se_squeeze/Mean_Squeeze__1241:0)
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.5.4) ./modules/dnn/src/onnx/onnx_importer.cpp:739: error: (-2:Unspecified error) in function 'handleNode'
> Node [Squeeze]:(model/block1a_se_squeeze/Mean_Squeeze__1241:0) parse error: OpenCV(4.5.4) ./modules/dnn/src/onnx/onnx_importer.cpp:1824: error: (-215:Assertion failed) node_proto.input_size() == 1 in function 'parseSqueeze'
>
Hi, I have the same issue. Is there any fix to this?
You need to export the model using opset 12 as already mentioned above. If you use the ultralytics convert.py it would be:
from ultralytics import YOLO
model = YOLO("yolov5m.pt") model.export(format="onnx", imgsz=[640,640], opset=12)
You need to export the model using opset 12 as already mentioned above. If you use the ultralytics convert.py it would be:
from ultralytics import YOLO
model = YOLO("yolov5m.pt") model.export(format="onnx", imgsz=[640,640], opset=12)
Hello, i tried using opset 12 but i am still receiving the same issue, is there any other solution to this?
I am also facing the same issue, I am getting the following issue.
cargo run Finished dev [unoptimized + debuginfo] target(s) in 0.02s Running
target/debug/onnx_cv [ERROR:0@0.052] global ./modules/dnn/src/onnx/onnx_importer.cpp (1018) handleNode DNN/ONNX: ERROR during processing node with 2 inputs and 1 outputs: [Add]:(onnx_node!/model.22/Add) from domain='ai.onnx' Invalid ONNX model.
then I check the model using Check Model, and says "The model is valid!",
then I check my model at Netron, the result is
System Information
OpenCV python version: 4.7.0 Operating System / Platform: Ubuntu 20.04 Python version: 3.8.10
Detailed description
The error happens when reading the .onnx model using cv2.dnn.readNet().
Whereas onnxruntime doesn't throw any error. Also this error seems similar to #23227 but with a different layer
Steps to reproduce
Model link - https://drive.google.com/file/d/10hET3jvdCBWyIHZR13lIXaKsQUiN2Wyz/view?usp=share_link
Issue submission checklist