opencv: OpenCV cannot import ONNX model: cv::dnn::dnn4_v20220524::Net::Impl::getLayerShapesRecursively Exception message: OpenCV(4.6.0-dev) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\layers\nary_eltwise_layers.cpp:116: error: (-215:Assertion failed) shape[i] == 1 || outShape[i] == 1 in function 'cv::dnn::NaryEltwiseLayerImpl::findCommonShape'
System Information
OpenCV => Python opencv-python-rolling 4.6.0.20220924 Operating System / Platform Windows 10 64 bit Python =>3.10.4
Detailed description
I converted two FastSeg models from Pytorch to ONNX and simplified the models. OpenCV cannot load the either the original nor simplified models. Failing with the following messages:
[ERROR:0@0.352] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\net_impl.cpp (1174) cv::dnn::dnn4_v20220524::Net::Impl::getLayerShapesRecursively input[0] = [ 1 128 256 128 ]
[ERROR:0@0.361] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\net_impl.cpp (1174) cv::dnn::dnn4_v20220524::Net::Impl::getLayerShapesRecursively input[1] = [ 1 128 128 256 ]
[ERROR:0@0.370] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\net_impl.cpp (1184) cv::dnn::dnn4_v20220524::Net::Impl::getLayerShapesRecursively Exception message: OpenCV(4.6.0-dev) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\layers\nary_eltwise_layers.cpp:116: error: (-215:Assertion failed) shape[i] == 1 || outShape[i] == 1 in function 'cv::dnn::NaryEltwiseLayerImpl::findCommonShape'```
### Steps to reproduce
Load model with the following code
``` Python
model = cv2.dnn.readNet(model_path)
One model provided here ans shared: https://drive.google.com/file/d/1uqMFcJKDEYSBNc4n-QvxSOe3KgwnMx7b/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)
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 26 (11 by maintainers)
@zihaomu Still investigating, but I think I have the problem.
This is about confusion in the (width, height) vs. (rows, columns) region for some of the models. It doesn’t help that when entering
cv2.dnn.blobFromImage(image, input_scale, input_size, mean, swapRB=False)
withinput_size = [1024, 512]
the result shape is shown asresult.shape (512, 1024)
.I will investigate further and post the results later.
I submitted a new issue for onnx-simplifier about the nodes with the same name here: https://github.com/daquexian/onnx-simplifier/issues/234