Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent shape for ConcatLayer in function 'getMemoryShapes' while reading onnx model #25485

Open
4 tasks done
gursimarsingh opened this issue Apr 24, 2024 · 5 comments
Open
4 tasks done
Assignees
Labels
bug category: dnn (onnx) ONNX suport issues in DNN module
Milestone

Comments

@gursimarsingh
Copy link

gursimarsingh commented Apr 24, 2024

System Information

Python 3.10.10
General configuration for OpenCV 4.6, 4.x and 5.x =====================================

Platform:
Host: Linux (Ubuntu 22.04) x86_64
CMake: 3.22.1
Configuration: Debug Release

Detailed description

Detailed description

Issue came up while adding a new onnx model dexiened for edge detection sample in dnn

onnx model can be downloaded from here

Model works perfectly when inferred with onnx and opencv==4.6.0

I get the following error with opencv==4.9.0-dev and opencv==5.x during model loading:

ERROR:0@1.272] global onnx_importer.cpp:1032 handleNode DNN/ONNX: ERROR during processing node with 6 inputs and 1 outputs: [Concat]:(onnx_node!Concat_146) from domain='ai.onnx'
terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.9.0-dev) opencv/modules/dnn/src/onnx/onnx_importer.cpp:1054: error: (-2:Unspecified error) in function 'handleNode'
> Node [Concat@ai.onnx]:(onnx_node!Concat_146) parse error: OpenCV(4.9.0-dev) opencv/modules/dnn/src/layers/concat_layer.cpp:108: error: (-201:Incorrect size of input array) Inconsistent shape for ConcatLayer in function 'getMemoryShapes'

Similar issues: #24030 , #19416

Steps to reproduce

Here is the inference snippet:

        session = cv.dnn.readNetFromONNX(args.onnxmodel)
        # Load and process the image using DexiNed model
        orig_img = cv.imread(cv.samples.findFile(args.input))
        # Prepocess the image
        img = preprocess(orig_img)
        
        inp = cv.dnn.blobFromImage(img, swapRB=False, crop=False)
    
        session.setInput(inp)

        out = session.forward()

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 any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)
@asmorkalov asmorkalov added the category: dnn (onnx) ONNX suport issues in DNN module label Apr 24, 2024
@asmorkalov asmorkalov added this to the 4.10.0 milestone Apr 24, 2024
@LaurentBerger
Copy link
Contributor

No error : you must simplify model :

onnxsim model(1).onnx a.sim.onnx
image
opencv onnx importer does not process dynamic shape. You have to substitue w and h

image

python -m onnxruntime.tools.make_dynamic_shape_fixed --dim_param w --dim_value 640 a.sim.onnx a1.onnx

python -m onnxruntime.tools.make_dynamic_shape_fixed --dim_param h --dim_value 480 a1.onnx a2.onnx

then
python

Python 3.10.10 (tags/v3.10.10:aad5f6a, Feb  7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2 as cv
>>> x = cv.dnn.readNet("a2.onnx")
>>> import numpy as np
>>> img =  np.zeros((1, 3, 480,640))
>>> x.setInput(img)
>>> w = x.forward()
>>>

@WanliZhong
Copy link
Member

WanliZhong commented Apr 30, 2024

This bug should be fixed if possible. dexiened is used to replace hed_pretrained_bsds model for edge detection. Do we have other public onnx models without manual modification for edge detection? Use public model link will save our traffic.

@LaurentBerger
Copy link
Contributor

This bug should be fixed if possible.

#19347 (comment)

@WanliZhong
Copy link
Member

This bug should be fixed if possible.

#19347 (comment)

OK, Thanks! Replaced model PR is crested #25515

@LaurentBerger
Copy link
Contributor

This bug should be fixed if possible.

bug fixed

@asmorkalov asmorkalov modified the milestones: 4.10.0, 5.0 May 20, 2024
@asmorkalov asmorkalov reopened this May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug category: dnn (onnx) ONNX suport issues in DNN module
Projects
None yet
Development

No branches or pull requests

5 participants