opencv / opencv

Open Source Computer Vision Library
https://opencv.org
Apache License 2.0
77.09k stars 55.68k forks source link

global onnx_importer.cpp:1051 handleNode DNN/ONNX: ERROR during processing node with 2 inputs and 1 outputs: [MatMul]:(onnx_node!MatMul_1) from domain='ai.onnx' #23227

Open pratap73 opened 1 year ago

pratap73 commented 1 year ago

System Information

OpenCV opencv-python-rolling 4.6.0.20221112 Operating System / Platform: Ubuntu 20.04 Python version: 3.9.12 onnx : 1.12

Detailed description

[ERROR:0@16.377] global onnx_importer.cpp:1051 handleNode DNN/ONNX: ERROR during processing node with 2 inputs and 1 outputs: [MatMul]:(onnx_node!p2o.MatMul.2) from domain='ai.onnx'

`OpenCV(4.7.0) /io/opencv/modules/dnn/src/onnx/onnx_importer.cpp:1073: error: (-2:Unspecified error) in function 'handleNode'

Node [MatMul@ai.onnx]:(onnx_node!p2o.MatMul.2) parse error: OpenCV(4.7.0) /io/opencv/modules/dnn/src/layers/fully_connected_layer.cpp:153: error: (-2:Unspecified error) in function 'virtual bool cv::dnn::FullyConnectedLayerImpl::getMemoryShapes(const std::vector<std::vector >&, int, std::vector<std::vector >&, std::vector<std::vector >&) const'

(expected: 'inputsTmp[0][i] == inputsTmp[1][i]'), where 'inputsTmp[0][i]' is 1 must be equal to 'inputsTmp[1][i]' is 0 `

when i use ppocr v3 rec model using opencv dnn readnet the above error occurs, onnx model link is given below https://drive.google.com/file/d/1BdGV-wYzEKBGogmLwHBFkJGwHWTMUnDx/view?usp=sharing

although it worked fine with the onnxruntime.

Steps to reproduce

install ppocr from paddleocr github repo. export the recognition model into onnx format using paddle2onnx.

then use open.dnn.readnet(rec_model.onnx) you will get the error

Issue submission checklist

asmorkalov commented 1 year ago

@WanliZhong Could you take a look on it?

fengyuentau commented 1 year ago

opencv-python-rolling 4.6.0.20221112

I think you should have a try with the lastest 4.7. You can either upgrade opencv-python-rolling or uninstall the old one then install opencv-python.

WanliZhong commented 1 year ago

@pratap73 Thanks for your feedback. I think this is a bug. OpenCV parse the inputs of onnx_node!p2o.MatMul.2 as 1x8x1x15 matmul 0x8x15. I will try to fix it. image

update: the dim is 0 or -1 means it's a dynamic shape

WanliZhong commented 1 year ago

@pratap73 I found that the input shape of this layer is dynamic, but currently OpenCV does not support this kind of model well. OpenCV 5.0 will solve such problems completely, so I think this issue will not be solved until 5.0 released.