opencv: OpenCV fails to import ONNX model: error: (-215:Assertion failed) !isDynamicShape in function 'cv::dnn::dnn4_v20220524::ONNXImporter::parseShape'

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 importing https://github.com/onnx/models/blob/main/vision/object_detection_segmentation/faster-rcnn/model/FasterRCNN-12.onnx into OpenCV the ONNXImporter fails.

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:

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 [ReduceMin@ai.onnx]:(2090) parse error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\dnn.cpp:621: error: 
(-2:Unspecified error) Can't create layer "2090" of type "ReduceMin" in function 'cv::dnn::dnn4_v20211220::LayerData::getLayerInstance'  
>
Steps to reproduce
  • Reproducible: yes
  • Enforceable: yes

Import the model using

model = cv2.dnn.readNetFromONNX(model_path)
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

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 24 (8 by maintainers)

Most upvoted comments

Hi @ukoehler, solving this problem requires full dynamic shape support, which conflicts with the existing engine, and we will fix this problem in the new inference engine of 5.x.

Issue is still in 4.7.0.68

error: OpenCV(4.7.0) /io/opencv/modules/dnn/src/onnx/onnx_importer.cpp:1073: error: (-2:Unspecified error) in function 'handleNode'
> Node [Shape@ai.onnx]:(onnx_node!Shape_35) parse error: OpenCV(4.7.0) /io/opencv/modules/dnn/src/onnx/onnx_importer.cpp:2630: error: (-215:Assertion failed) !isDynamicShape in function 'parseShape'

Unbelievable, is it impossible to use OpenCV DNN for inference?

Issue is still in opencv-python-rolling-4.6.0.20221112.