Skip to content

OpenCV fails to import ONNX model #22015

@ukoehler

Description

@ukoehler
System information (version)
  • OpenCV => 4.5.5
  • Operating System / Platform => Windows 10 64 bit
  • Compiler => Python 3.10.4
  • Installed packages:

numpy 1.22.3
opencv-contrib-python 4.5.5.64
pip 22.0.4
setuptools 58.1.0

Detailed description

When running the demo.py for opencv_zoo/models/image_classification_mobilenet/ the models fails to import. All the other models I tried to import did work well.

I wrote a Python script in a different venv to check the model with onnx and infer with the model with onnxruntime. The model imports and executes fine. This is not a problem with the models, but with the importer.

Error message:

[ERROR:0@0.223] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\o
nnx\onnx_importer.cpp (909) cv::dnn::dnn4_v20211220::ONNXImporter::handleNode DN
N/ONNX: ERROR during processing node with 3 inputs and 1 outputs: [Clip]:(317) f
rom domain='ai.onnx'
Traceback (most recent call last):
  File "D:\Local\devel\Python\OpenCV\image_classification_mobilenet\demo.py", li
ne 41, in <module>
    'v2': MobileNetV2(modelPath='./image_classification_mobilenetv2_2022apr.onnx
', labelPath=args.label, backendId=args.backend, targetId=args.target),
  File "D:\Local\devel\Python\OpenCV\image_classification_mobilenet\mobilenet_v2
.py", line 11, in __init__
    self.model = cv.dnn.readNet(self.model_path)
cv2.error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src
\onnx\onnx_importer.cpp:928: error: (-2:Unspecified error) in function 'cv::dnn:
:dnn4_v20211220::ONNXImporter::handleNode'
> Node [Clip@ai.onnx]:(317) parse error: OpenCV(4.5.5) D:\a\opencv-python\opencv
-python\opencv\modules\dnn\src\onnx\onnx_importer.cpp:1613: error: (-2:Unspecifi
ed error) in function 'void __cdecl cv::dnn::dnn4_v20211220::ONNXImporter::parse
Clip(class cv::dnn::dnn4_v20211220::LayerParams &,const class opencv_onnx::NodeP
roto &)'
> >  (expected: 'node_proto.input_size() == 1'), where
> >     'node_proto.input_size()' is 3
> > must be equal to
> >     '1' is 1
>
Steps to reproduce
  • Reproducible: yes
  • Enforceable: yes

Run the provided demo.py in opencv_zoo/models/image_classification_mobilenet/

Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions