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

ERROR on cv::dnn::readNetFromONNX(..) during processing node [Gather] with 2 inputs and 1 outputs #20866

Closed
4 tasks done
rayray41414141 opened this issue Oct 13, 2021 · 2 comments

Comments

@rayray41414141
Copy link

System information (version)

  • OpenCV => 4.5.4
  • Operating System / Platform => Windows 64 Bit
  • Compiler => VisualStudio 2019

Detailed description

I have created a model in tensorflow and converted it to onnx with tf2onnx.
It seems like the interpreter cannot parse the gather node.
The following error is thown on cv::dnn::readNetFromONNX(..):

[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp (602) cv::dnn::dnn4_v20211004::ONNXImporter::populateNet DNN/ONNX: loading ONNX v7 model produced by 'tf2onnx':1.10.0. Number of nodes = 212, inputs = 1, outputs = 1
OpenCV(4.5.4) Error: Assertion failed (indexMat.total() == 1) in cv::dnn::dnn4_v20211004::ONNXImporter::parseGather, file C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp, line 2200
[ERROR:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp (720) cv::dnn::dnn4_v20211004::ONNXImporter::handleNode DNN/ONNX: ERROR during processing node with 2 inputs and 1 outputs: [Gather]:(Shape__224:0)
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp (724) cv::dnn::dnn4_v20211004::ONNXImporter::handleNode     Input[0] = 'Shape__820:0'
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp (724) cv::dnn::dnn4_v20211004::ONNXImporter::handleNode     Input[1] = 'Const__872'
[ INFO:0] global C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp (728) cv::dnn::dnn4_v20211004::ONNXImporter::handleNode     Output[0] = 'Shape__224:0'
OpenCV(4.5.4) Error: Unspecified error (> Node [Gather]:(Shape__224:0) parse error: OpenCV(4.5.4) C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp:2200: error: (-215:Assertion failed) indexMat.total() == 1 in function 'cv::dnn::dnn4_v20211004::ONNXImporter::parseGather'
> ) in cv::dnn::dnn4_v20211004::ONNXImporter::handleNode, file C:\build\master_winpack-build-win64-vc15\opencv\modules\dnn\src\onnx\onnx_importer.cpp, line 739

Convertion was performed using this command:
python -m tf2onnx.convert --keras .\saved_model\ --output .\models\tf2onnx_keras.onnx --opset 14

Here the node from the error log. netron.app.

grafik

Steps to reproduce

Onnx model:
tf2onnx_keras.zip

The Code:

auto onnx_model = cv::dnn::readNetFromONNX("tf2onnx_keras.onnx");

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
@rayray41414141
Copy link
Author

I do have dynamic input shape.
Maybe I've got the same problem like #19347?

@alalek
Copy link
Member

alalek commented Dec 23, 2021

Problem is similar to #19347

There is Shape node (Shape__820:0) with dynamic input (non-constant during model importing). These cases are not supported yet in OpenCV.

Lets track progress in one issue: #19347

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants