error: OpenCV(4.2.0) error: (-201:Incorrect size of input array) Inconsistent shape for ConcatLayer in function ‘cv::dnn::ConcatLayerImpl::getMemoryShapes

System information (version)
  • OpenCV => 4.2
  • Operating System / Platform => Windows 64 Bit
  • Compiler => Anaconda Python
Detailed description

error: OpenCV(4.2.0) C:\projects\opencv-python\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

I am using the OpenCV DNN module to do some predictions on images but in OpenCV 4.2 it’s not working and giving me this error above. The same happens with Google Colab where OpenCV 4.2 is installed by default but as soon as I changed it to 4.1.0 it works right away. The error is also there from version 4.1.2 to 4.4.0, I didn’t check every version in between but I did check the latest.

Steps to reproduce

https://colab.research.google.com/drive/1ciNEO_WbG6W72U1GOa6-jCOeAxBoz5VC?usp=sharing

Just run the cells in this notebook to reproduce the error. Do not run the first cell to see the error. Run it after you see the error so you see that everything works fine in 4.1.0

Issue submission checklist
  • I report the issue, it’s not a question
  • I checked the problem with documentation, FAQ, open issues,
    answers.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

1 possible answer(s) on “error: OpenCV(4.2.0) error: (-201:Incorrect size of input array) Inconsistent shape for ConcatLayer in function ‘cv::dnn::ConcatLayerImpl::getMemoryShapes

  1. Text graph for the SSD Mobilenet V2 model obtained with:

    gdown --id 1a-1vXD2K-XoVFYS_jl93zjKu3LyTi4O6
    

    causes this error. I’ve regenerated the text graph using tf_text_graph_ssd.py OpenCV tool:

    python tf_text_graph_ssd.py --input <YOUR_PATH>/ssd_mobilenet_v2_coco_2018_03_29/frozen_inference_graph.pb --config <YOUR_PATH>/ssd_mobilenet_v2_coco_2018_03_29/pipeline.config --output <YOUR_PATH>/ssd_mobilenet_v2_graph.pbtxt
    

    then the pipeline from the attached colab notebook passed (ssd_mobilenet_v2_graph.zip).

    It should be noticed that there is a helpful OpenCV resource: “TensorFlow Object Detection API”. It contains details about running TF object detection models with OpenCV and also a list of tested TF detection models and their text graphs.