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

OpenCV cannot import ONNX model: Can't create layer "..." of type "TopK" #22890

Open
4 tasks done
ukoehler opened this issue Nov 30, 2022 · 5 comments · May be fixed by #23279
Open
4 tasks done

OpenCV cannot import ONNX model: Can't create layer "..." of type "TopK" #22890

ukoehler opened this issue Nov 30, 2022 · 5 comments · May be fixed by #23279
Assignees
Labels
bug category: dnn (onnx) ONNX suport issues in DNN module category: dnn

Comments

@ukoehler
Copy link

System Information

OpenCV => Python opencv-python-rolling 4.6.0.20221112 (no update available)
Operating System / Platform Windows 10 64 bit
Python =>3.10.4

Detailed description

I converted the PointRend from PaddleSeg to ONNX:

https://github.com/PaddlePaddle/PaddleSeg/tree/release/2.7/configs/pointrend

This fails to load in OpenCV 4.6 pre-release:

[ERROR:0@0.392] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\onnx\onnx_importer.cpp (1053) cv::dnn::dnn4_v20220524::ONNXImporter::handleNode DNN/ONNX: ERROR during processing node with 2 inputs and 2 outputs: [TopK]:(onnx_node!p2o.TopK.0) from domain='ai.onnx'
Traceback (most recent call last):
  File "d:\Local\devel\Python\OpenCV\dnn_segmentation_paddle_pointrend_voc\inference.py", line 131, in <module>
    model = cv2.dnn.readNet(model_path)
cv2.error: OpenCV(4.6.0-dev) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\onnx\onnx_importer.cpp:1072: error: (-2:Unspecified error) in function 'cv::dnn::dnn4_v20220524::ONNXImporter::handleNode'
> Node [TopK@ai.onnx]:(onnx_node!p2o.TopK.0) parse error: OpenCV(4.6.0-dev) d:\a\opencv-python\opencv-python\opencv\modules\dnn\src\net_impl.hpp:107: error: (-2:Unspecified error) Can't create layer "onnx_node!p2o.TopK.0" of type "TopK" in function 'cv::dnn::dnn4_v20220524::Net::Impl::getLayerInstance'

Same result with the model after onnx simplify.

Steps to reproduce

model = cv2.dnn.readNet(model_path)

Find the ONNX file here: https://drive.google.com/file/d/1rKcUtoncMvorMtk6LdC6_QK2PSRS_pee/view?usp=sharing

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)
@ukoehler ukoehler added the bug label Nov 30, 2022
@fengyuentau
Copy link
Member

We do not have the support of TopK in DNN for now. Let me take a look into the problem later.

@fengyuentau fengyuentau self-assigned this Dec 1, 2022
@fengyuentau fengyuentau added category: dnn category: dnn (onnx) ONNX suport issues in DNN module labels Dec 1, 2022
@fengyuentau
Copy link
Member

This model contains two kinds of TopK operators, one of which has a constant input K, but the other of which does not. We can only add the support for the former case in the current DNN engine. However, as I looked into the model, I found at least two more problems:

  • Range operators with non-constant inputs cannot be supported by the current DNN engine.
  • GridSample operators are not supported.

@ukoehler
Copy link
Author

Still failing in opencv-python-rolling-4.7.0.68

@vavanade
Copy link

Same problem here on opencv-python==4.7.0.68.

global onnx_importer.cpp:1051 handleNode DNN/ONNX: ERROR during processing node with 2 inputs and 2 outputs: [TopK]:(onnx_node!/TopK) from domain='ai.onnx'

@fengyuentau fengyuentau linked a pull request Feb 20, 2023 that will close this issue
9 tasks
@ukoehler
Copy link
Author

Still not working in opencv-python-rolling-4.8.0.20230624

Note to self: \Local\devel\Python\OpenCV\dnn_segmentation_paddle_pointrend_voc\inference.py

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 category: dnn
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants