Open stereomatchingkiss opened 1 year ago
The same issue with both attached models:
./opencv_model_diagnostics -m=./ch_PP-OCRv3_rec_simple.onnx
[ERROR:0@0.072] global onnx_importer.cpp:1014 handleNode DNN/ONNX: Potential problem during processing node with 5 inputs and 1 outputs: [Slice]:(onnx_node!p2o.Slice.0) from domain='ai.onnx'
OpenCV(4.9.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/onnx/onnx_importer.cpp:1232: error: (-215:Assertion failed) constBlobs.find(node_proto.input(i)) != constBlobs.end() in function 'parseSlice'
[ERROR:0@0.072] global onnx_importer.cpp:1014 handleNode DNN/ONNX: Potential problem during processing node with 2 inputs and 1 outputs: [Concat]:(onnx_node!p2o.Concat.0) from domain='ai.onnx'
OpenCV(4.9.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/layers/concat_layer.cpp:105: error: (-215:Assertion failed) curShape.size() == outputs[0].size() in function 'getMemoryShapes'
[ERROR:0@0.072] global onnx_importer.cpp:1014 handleNode DNN/ONNX: Potential problem during processing node with 2 inputs and 1 outputs: [Reshape]:(onnx_node!p2o.Reshape.8) from domain='ai.onnx'
OpenCV(4.9.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/onnx/onnx_importer.cpp:597: error: (-5:Bad argument) Blob p2o.Concat.1 not found in const blobs in function 'getBlob'
[ERROR:0@0.073] global onnx_importer.cpp:1014 handleNode DNN/ONNX: Potential problem during processing node with 1 inputs and 1 outputs: [Transpose]:(onnx_node!p2o.Transpose.0) from domain='ai.onnx'
OpenCV(4.9.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/layers/permute_layer.cpp:162: error: (-215:Assertion failed) (int)_numAxes == inputs[0].size() in function 'getMemoryShapes'
[ERROR:0@0.074] global onnx_importer.cpp:1014 handleNode DNN/ONNX: Potential problem during processing node with 2 inputs and 1 outputs: [Concat]:(onnx_node!p2o.Concat.2) from domain='ai.onnx'
OpenCV(4.9.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/layers/concat_layer.cpp:109: error: (-201:Incorrect size of input array) Inconsistent shape for ConcatLayer in function 'getMemoryShapes'
[ERROR:0@0.075] global onnx_importer.cpp:1014 handleNode DNN/ONNX: Potential problem during processing node with 3 inputs and 1 outputs: [Conv]:(onnx_node!p2o.Conv.34) from domain='ai.onnx'
OpenCV(4.9.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/layers/convolution_layer.cpp:396: error: (-2:Unspecified error) Number of input channels should be multiple of 1024 but got 512 in function 'getMemoryShapes'
[ERROR:0@0.082] global onnx_importer.cpp:1014 handleNode DNN/ONNX: Potential problem during processing node with 1 inputs and 1 outputs: [Transpose]:(onnx_node!p2o.Transpose.8) from domain='ai.onnx'
OpenCV(4.9.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/layers/permute_layer.cpp:162: error: (-215:Assertion failed) (int)_numAxes == inputs[0].size() in function 'getMemoryShapes'
[ERROR:0@0.082] global onnx_importer.cpp:1014 handleNode DNN/ONNX: Potential problem during processing node with 2 inputs and 1 outputs: [MatMul]:(onnx_node!p2o.MatMul.24) from domain='ai.onnx'
OpenCV(4.9.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/layers/matmul_layer.cpp:65: error: (-2:Unspecified error) in function 'virtual bool cv::dnn::MatMulLayerImpl::getMemoryShapes(const std::vector<std::vector<int> >&, int, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&) const'
> DNN/MatMul: invalid dimension K (expected: 'K_A == K_B'), where
> 'K_A' is 1
> must be equal to
> 'K_B' is 64
The same issue with both attached models:
./opencv_model_diagnostics -m=./ch_PP-OCRv3_rec_simple.onnx [ERROR:0@0.072] global onnx_importer.cpp:1014 handleNode DNN/ONNX: Potential problem during processing node with 5 inputs and 1 outputs: [Slice]:(onnx_node!p2o.Slice.0) from domain='ai.onnx' OpenCV(4.9.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/onnx/onnx_importer.cpp:1232: error: (-215:Assertion failed) constBlobs.find(node_proto.input(i)) != constBlobs.end() in function 'parseSlice' [ERROR:0@0.072] global onnx_importer.cpp:1014 handleNode DNN/ONNX: Potential problem during processing node with 2 inputs and 1 outputs: [Concat]:(onnx_node!p2o.Concat.0) from domain='ai.onnx' OpenCV(4.9.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/layers/concat_layer.cpp:105: error: (-215:Assertion failed) curShape.size() == outputs[0].size() in function 'getMemoryShapes' [ERROR:0@0.072] global onnx_importer.cpp:1014 handleNode DNN/ONNX: Potential problem during processing node with 2 inputs and 1 outputs: [Reshape]:(onnx_node!p2o.Reshape.8) from domain='ai.onnx' OpenCV(4.9.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/onnx/onnx_importer.cpp:597: error: (-5:Bad argument) Blob p2o.Concat.1 not found in const blobs in function 'getBlob' [ERROR:0@0.073] global onnx_importer.cpp:1014 handleNode DNN/ONNX: Potential problem during processing node with 1 inputs and 1 outputs: [Transpose]:(onnx_node!p2o.Transpose.0) from domain='ai.onnx' OpenCV(4.9.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/layers/permute_layer.cpp:162: error: (-215:Assertion failed) (int)_numAxes == inputs[0].size() in function 'getMemoryShapes' [ERROR:0@0.074] global onnx_importer.cpp:1014 handleNode DNN/ONNX: Potential problem during processing node with 2 inputs and 1 outputs: [Concat]:(onnx_node!p2o.Concat.2) from domain='ai.onnx' OpenCV(4.9.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/layers/concat_layer.cpp:109: error: (-201:Incorrect size of input array) Inconsistent shape for ConcatLayer in function 'getMemoryShapes' [ERROR:0@0.075] global onnx_importer.cpp:1014 handleNode DNN/ONNX: Potential problem during processing node with 3 inputs and 1 outputs: [Conv]:(onnx_node!p2o.Conv.34) from domain='ai.onnx' OpenCV(4.9.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/layers/convolution_layer.cpp:396: error: (-2:Unspecified error) Number of input channels should be multiple of 1024 but got 512 in function 'getMemoryShapes' [ERROR:0@0.082] global onnx_importer.cpp:1014 handleNode DNN/ONNX: Potential problem during processing node with 1 inputs and 1 outputs: [Transpose]:(onnx_node!p2o.Transpose.8) from domain='ai.onnx' OpenCV(4.9.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/layers/permute_layer.cpp:162: error: (-215:Assertion failed) (int)_numAxes == inputs[0].size() in function 'getMemoryShapes' [ERROR:0@0.082] global onnx_importer.cpp:1014 handleNode DNN/ONNX: Potential problem during processing node with 2 inputs and 1 outputs: [MatMul]:(onnx_node!p2o.MatMul.24) from domain='ai.onnx' OpenCV(4.9.0-dev) /home/alexander/Projects/OpenCV/opencv-master/modules/dnn/src/layers/matmul_layer.cpp:65: error: (-2:Unspecified error) in function 'virtual bool cv::dnn::MatMulLayerImpl::getMemoryShapes(const std::vector<std::vector<int> >&, int, std::vector<std::vector<int> >&, std::vector<std::vector<int> >&) const' > DNN/MatMul: invalid dimension K (expected: 'K_A == K_B'), where > 'K_A' is 1 > must be equal to > 'K_B' is 64
I checked both models and found that they have dynamic batch and width. It would not work with dnn if input is of variable shape. Using onnxsim
to overwrite input shape can resolve this problem:
$ onnxsim --overwrite-input-shape=1,3,48,48 model.onnx model.fixed.sim.onnx
Simplifying...
Finish! Here is the difference:
┏━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━┓
┃ ┃ Original Model ┃ Simplified Model ┃
┡━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━┩
│ Add │ 50 │ 50 │
│ AveragePool │ 1 │ 1 │
│ BatchNormalization │ 32 │ 0 │
│ Clip │ 27 │ 27 │
│ Concat │ 2 │ 1 │
│ Constant │ 356 │ 116 │
│ Conv │ 36 │ 36 │
│ Div │ 32 │ 32 │
│ GlobalAveragePool │ 2 │ 2 │
│ HardSigmoid │ 2 │ 2 │
│ MatMul │ 13 │ 13 │
│ Mul │ 50 │ 43 │
│ Pow │ 5 │ 5 │
│ ReduceMean │ 10 │ 10 │
│ Relu │ 2 │ 2 │
│ Reshape │ 6 │ 6 │
│ Shape │ 1 │ 0 │
│ Sigmoid │ 7 │ 7 │
│ Slice │ 7 │ 6 │
│ Softmax │ 3 │ 3 │
│ Sqrt │ 5 │ 5 │
│ Squeeze │ 7 │ 7 │
│ Sub │ 5 │ 5 │
│ Transpose │ 9 │ 9 │
│ Model Size │ 10.2MiB │ 10.1MiB │
└────────────────────┴────────────────┴──────────────────┘
$ python
Python 3.10.9 (main, Jan 11 2023, 09:18:18) [Clang 14.0.6 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2 as cv
>>> cv.dnn.readNet("model.fixed.sim.onnx")
< cv2.dnn.Net 0x1283e4450>
System Information
OpenCV version: 4.8.0 operation System : windows11 compiler : visual c++ 2019
Detailed description
Error messages
Steps to reproduce
Steps to reproduce:
cv::dnn::readNet("ch_PP-OCRv3_rec_simple.onnx");
Model after onnx simplify Model before onnx simplify
Issue submission checklist