Skip to content

dnn error: (-201:Incorrect size of input array) Inconsistent shape for ConcatLayer in function 'getMemoryShapes' #19416

@SunlifeV

Description

@SunlifeV
  • OpenCV => 4.5.1
  • Operating System / Platform => Windows 64 Bit
  • Compiler => MinGW 7.3 & Python 3.6
Detailed description

In Python and C++ , using the readNet (path) function of opencv (4.5.1) to load the model, the following errors occurred respectively

OpenCV(4.5.1) opencv\modules\dnn\src\onnx\onnx_importer.cpp:1887:
error: (-2:Unspecified error) in function 'cv::dnn::dnn4_v20201117::ONNXImporter::handleNode'
> Node [Concat]:(131) parse error: OpenCV(4.5.1) \opencv\modules\dnn\src\layers\concat_layer.cpp:102: 
error: (-201:Incorrect size of input array) Inconsistent shape for ConcatLayer
in function 'cv::dnn::ConcatLayerImpl::getMemoryShapes'
> 
 File "F:\pythonProject\test\convert_to_onnx.py", line 100, in <module>
   cv2.dnn.readNet(os.path.dirname(os.path.realpath(__file__))+"/demo.onnx")
[ERROR:0] global F:\OpenCV\opencv-master\sources\modules\dnn\src\onnx\onnx_importer.cpp (1928) handleNode DNN/ONNX: 
ERROR during processing node with 4 inputs and 1 outputs: [Concat]:(131)

OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.5.1-dev) Error: Unspecified error (> Node [Concat]:(131) parse error: OpenCV(4.5.1-dev) 
F:\OpenCV\opencv-master\sources\modules\dnn\src\layers\concat_layer.cpp:102: 
error: (-201:Incorrect size of input array) Inconsistent shape for ConcatLayer in function 'getMemoryShapes'
> ) in handleNode, file F:\OpenCV\opencv-master\sources\modules\dnn\src\onnx\onnx_importer.cpp, line 1937

This is the onnx model I use.
demo.zip

Steps to reproduce

Python code

    input_names = ["input0"]
    output_names = ["output0"]
 
    x = torch.randn(1,3,24,94, requires_grad=True).to(device)
 
    # Export the model
    torch.onnx.export( net,  # model being run
                  x,  # model input (or a tuple for multiple inputs)
                  os.path.dirname(os.path.realpath(__file__))+"/demo.onnx",  # where to save the model (can be a file or file-like object)
                  export_params=True,  # store the trained parameter weights inside the model file
                  opset_version=11,  # the ONNX version to export the model to
                  do_constant_folding=True,  # whether to execute constant folding for optimization
                  input_names=input_names,  # the model's input names
                  output_names=output_names,  # the model's output names
                  #dynamic_axes=dynamic_axes
                  )
    cv2.dnn.readNet(os.path.dirname(os.path.realpath(__file__))+"/demo.onnx")

C++ code

Net net;
net = readNet("demo.onnx");

The following is part of the print information.

[DEBUG:0] global F:\OpenCV\opencv-master\sources\modules\dnn\src\onnx\onnx_importer.cpp (460) handleNode DNN/ONNX: processing node with 2 inputs and 1 outputs: [Pow]:(123)
[DEBUG:0] global F:\OpenCV\opencv-master\sources\modules\dnn\src\onnx\onnx_importer.cpp (460) handleNode DNN/ONNX: processing node with 1 inputs and 1 outputs: [ReduceMean]:(124)
[DEBUG:0] global F:\OpenCV\opencv-master\sources\modules\dnn\src\onnx\onnx_importer.cpp (460) handleNode DNN/ONNX: processing node with 2 inputs and 1 outputs: [Div]:(125)
[DEBUG:0] global F:\OpenCV\opencv-master\sources\modules\dnn\src\onnx\onnx_importer.cpp (460) handleNode DNN/ONNX: processing node with 2 inputs and 1 outputs: [Pow]:(128)
[DEBUG:0] global F:\OpenCV\opencv-master\sources\modules\dnn\src\onnx\onnx_importer.cpp (460) handleNode DNN/ONNX: processing node with 1 inputs and 1 outputs: [ReduceMean]:(129)
[DEBUG:0] global F:\OpenCV\opencv-master\sources\modules\dnn\src\onnx\onnx_importer.cpp (460) handleNode DNN/ONNX: processing node with 2 inputs and 1 outputs: [Div]:(130)
[DEBUG:0] global F:\OpenCV\opencv-master\sources\modules\dnn\src\onnx\onnx_importer.cpp (460) handleNode DNN/ONNX: processing node with 4 inputs and 1 outputs: [Concat]:(131)
[ERROR:0] global F:\OpenCV\opencv-master\sources\modules\dnn\src\onnx\onnx_importer.cpp (1928) handleNode DNN/ONNX: ERROR during processing node with 4 inputs and 1 outputs: [Concat]:(131)
[ INFO:0] global F:\OpenCV\opencv-master\sources\modules\dnn\src\onnx\onnx_importer.cpp (1931) handleNode     Input[0] = '109'
[ INFO:0] global F:\OpenCV\opencv-master\sources\modules\dnn\src\onnx\onnx_importer.cpp (1931) handleNode     Input[1] = '117'
[ INFO:0] global F:\OpenCV\opencv-master\sources\modules\dnn\src\onnx\onnx_importer.cpp (1931) handleNode     Input[2] = '125'
[ INFO:0] global F:\OpenCV\opencv-master\sources\modules\dnn\src\onnx\onnx_importer.cpp (1931) handleNode     Input[3] = '130'
[ INFO:0] global F:\OpenCV\opencv-master\sources\modules\dnn\src\onnx\onnx_importer.cpp (1935) handleNode     Output[0] = '131'
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 solution
  • I updated to latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions