opencv: onnx 12: Inconsistent shape for ConcatLayer in function 'cv::dnn::ConcatLayerImpl::getMemoryShapes'

I’m working on a Unet model and the upsampling layers will trigger an exception when infering on an image with a different size than the training dataset: Inconsistent shape for ConcatLayer in function 'cv::dnn::ConcatLayerImpl::getMemoryShapes' When exporting to onnx opset 9, inference work for any input size. The upsampling layer is defined as Upsample image

When exporting to onnx opset >9, inference work on 256² only. The upsampling layer is defined as Resize image

I can provide both onnx by email if needed

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 22 (22 by maintainers)

Commits related to this issue

Most upvoted comments

Ok so I exported both models with different opset, this is what I got

when giving size & opset  9 -> Upsample [X, scales]
when giving size & opset 10 -> Resize   [X, scales]
when giving size & opset 11 -> Resize   [X, roi, scales, sizes]

when giving scales & opset  9 -> Upsample [X, scales]
when giving scales & opset 10 -> Resize   [X, scales]
when giving scales & opset 11 -> Resize   [X, roi, scales]

So I could change my PR to this:

            int opset = model_proto.has_ir_version() ? (int)model_proto.ir_version() : -1;
            Mat scales;
            switch (opset)
            {
                case 12:
                case 11: scales = getBlob(node_proto, 2); break;
                default: scales = getBlob(node_proto, 1); break;
            }

Yes, I think it’s easier to understand. But you need a change:

layerParams.set("width", shapes[3]);
layerParams.set("height", shapes[2]);

I confirm that editing my onnx and adding “zoom_factor_x”, “zoom_factor_y” will make it work. So what we would need is to read from scales input instead

EDIT: which seems to be done here: https://github.com/opencv/opencv/blob/199687a1c5b194481754d3efe14cb06a82efa805/modules/dnn/src/onnx/onnx_importer.cpp#L1689-L1700