Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCV cannot import ONNX model: (outShape[2 + i] - 1) * strides[i] < inpShape[i] + pads_end[i] #22900

Open
4 tasks done
ukoehler opened this issue Dec 1, 2022 · 7 comments
Open
4 tasks done
Assignees
Labels
bug category: dnn (onnx) ONNX suport issues in DNN module
Milestone

Comments

@ukoehler
Copy link

ukoehler commented Dec 1, 2022

System Information

OpenCV => Python opencv-python-rolling 4.6.0.20221112 (no update available)
Operating System / Platform Windows 10 64 bit
Python =>3.10.4

Detailed description

I converted the Portrait PP-HumanSegV1-Lite from PaddleSeg to ONNX (the model load in netron without complaints):

https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.7/contrib/PP-HumanSeg

This fails to load in OpenCV 4.6 pre-release:

[ERROR:0@0.068] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\onnx\onnx_importer.cpp (1053) cv::dnn::dnn4_v20220524::ONNXImporter::handleNode DNN/ONNX: ERROR during processing node with 1 inputs and 1 outputs: [MaxPool]:(onnx_node!p2o.MaxPool.0) from domain='ai.onnx'
Traceback (most recent call last):
  File "d:\Local\devel\Python\OpenCV\dnn_segmentation_paddle_portrait_pp_humansegv1_lite\inference.py", line 131, in <module>
    model = cv2.dnn.readNet(model_path)
cv2.error: OpenCV(4.6.0-dev) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\onnx\onnx_importer.cpp:1072: error: (-2:Unspecified error) in function 'cv::dnn::dnn4_v20220524::ONNXImporter::handleNode'
> Node [MaxPool@ai.onnx]:(onnx_node!p2o.MaxPool.0) parse error: OpenCV(4.6.0-dev) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\layers\pooling_layer.cpp:1335: error: (-215:Assertion failed) (outShape[2 + i] - 1) * strides[i] < inpShape[i] + pads_end[i] in function 'cv::dnn::PoolingLayerImpl::getMemoryShapes'

Steps to reproduce

model = cv2.dnn.readNet(model_path)

Find the ONNX file here: https://drive.google.com/file/d/1HieIVf2HLW3-e_ggmMgVote1pvFQEGuG/view?usp=sharing

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)
@ukoehler ukoehler added the bug label Dec 1, 2022
@asmorkalov asmorkalov added the category: dnn (onnx) ONNX suport issues in DNN module label Dec 1, 2022
@asmorkalov
Copy link
Contributor

I tried the network with diagnostic tool and It looks like pooling issue already fixed in 4.x. There are more issues that prevent from loading with OpenCV:

  • Dynamic shape. OpenCV does not support it for now.
  • Resize interpolation type.
[ERROR:0@0.026] global /mnt/projects/Projects/OpenCV/opencv-master/modules/dnn/src/onnx/onnx_importer.cpp (1045) handleNode DNN/ONNX: Layer of type Resize(Resize) cannot be created with parameters coordinate_transformation_mode : half_pixel
depth : 5
has_dynamic_shapes : 0
mode : linear
. Error: OpenCV(4.6.0-dev) /mnt/projects/Projects/OpenCV/opencv-master/modules/dnn/include/opencv2/dnn/dnn.inl.hpp:350: error: (-204:Requested object was not found) Required argument "interpolation" not found into dictionary in function 'get'

[ERROR:0@0.027] global /mnt/projects/Projects/OpenCV/opencv-master/modules/dnn/src/onnx/onnx_importer.cpp (2611) parseShape DNN/ONNX(Shape): dynamic 'zero' shapes are not supported, input relu_30.tmp_0 [ 1 2 0 0 ]

@ukoehler
Copy link
Author

ukoehler commented Dec 5, 2022

Hi @asmorkalov ,

I just checked and no newer version of OpenCV 4.x is available. Then I do not understand the remark about the pooling issue.

Give the additional problems, I guess there is no chance to get this working in the near future?

Cheers

Uwe

@ukoehler
Copy link
Author

Still failing in opencv-python-rolling-4.7.0.68

@ukoehler
Copy link
Author

Still failing in opencv_python_rolling-4.8.0.20230624

Note to self: \Local\devel\Python\OpenCV\dnn_segmentation_paddle_portrait_pp_humansegv1_lite\inference.py

@asmorkalov asmorkalov added this to the 4.9.0 milestone Jul 11, 2023
@asmorkalov
Copy link
Contributor

@Abdurrahheem could you take a look on it?

@asmorkalov asmorkalov modified the milestones: 4.9.0, 4.10.0 Dec 19, 2023
@asmorkalov asmorkalov modified the milestones: 4.10.0, 4.11.0 May 16, 2024
@Abdurrahheem
Copy link
Contributor

@ukoehler 4.x does not support dinamic shapes currently. So the best option for now would be to use OpenCV 5 and set graph to new as follows export OPENCV_FORCE_DNN_ENGINE=2. I have checked your sample on OpenCV 5.x, it works just fine.

@asmorkalov
Copy link
Contributor

export OPENCV_FORCE_DNN_ENGINE=2 is not required. The new engine is used by default.

@Abdurrahheem Abdurrahheem reopened this Dec 18, 2024
@asmorkalov asmorkalov modified the milestones: 4.11.0, 5.0-release Dec 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug category: dnn (onnx) ONNX suport issues in DNN module
Projects
None yet
Development

No branches or pull requests

3 participants