-
-
Notifications
You must be signed in to change notification settings - Fork 55.9k
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
ONNX broken for identity function #25763
Comments
@Abdurrahheem could you take a look? |
Error cases are:
Let me explain one by one.
|
Do you mean that the errors for 0 and 1 dimensions are expected? I feels like a very bad bug to me, and it will leave ONNX integration in a broken state until fixed. So I hope this is not considered expected by OpenCV devs. OpenCV 4.10 is latest released version, so I am not sure how to test your hypothesis for 5.x without more help. Can you please confirm that this is fixed in 5.x? If that is the case I think it should be back-ported to 4.11 as well. |
0d/1d mat support is introduced since 5.x. It was a big patch and breaks some existing things. So maybe not a good idea to do a backport. |
@fengyuentau Ok good point. Is the fix for 3d input also not backwards compatible or can it be included in 4.x? |
The 3d issue is not handle yet in either branch. |
…in_dnn python: attempts to fix 3d mat parsing problem for dnn #25810 Fixes #25762 #23242 Relates #25763 #19091 Although `cv.Mat` has already been introduced to workaround this problem, people do not know it and it kind of leads to confusion with `numpy.array`. This patch adds a "switch" to turn off the auto multichannel feature when the API is from cv::dnn::Net (more specifically, `setInput`) and the parameter is of type `Mat`. This patch only leads to changes of three places in `pyopencv_generated_types_content.h`: ```.diff static PyObject* pyopencv_cv_dnn_dnn_Net_setInput(PyObject* self, PyObject* py_args, PyObject* kw) { ... - pyopencv_to_safe(pyobj_blob, blob, ArgInfo("blob", 0)) && + pyopencv_to_safe(pyobj_blob, blob, ArgInfo("blob", 8)) && ... } // I guess we also need to change this as one-channel blob is expected for param static PyObject* pyopencv_cv_dnn_dnn_Net_setParam(PyObject* self, PyObject* py_args, PyObject* kw) { ... - pyopencv_to_safe(pyobj_blob, blob, ArgInfo("blob", 0)) ) + pyopencv_to_safe(pyobj_blob, blob, ArgInfo("blob", 8)) ) ... - pyopencv_to_safe(pyobj_blob, blob, ArgInfo("blob", 0)) ) + pyopencv_to_safe(pyobj_blob, blob, ArgInfo("blob", 8)) ) ... } ``` Others are unchanged, e.g. `dnn_SegmentationModel` and stuff like that. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
|
@fengyuentau I will try out asap :) |
…d_mat_in_dnn python: attempts to fix 3d mat parsing problem for dnn opencv#25810 Fixes opencv#25762 opencv#23242 Relates opencv#25763 opencv#19091 Although `cv.Mat` has already been introduced to workaround this problem, people do not know it and it kind of leads to confusion with `numpy.array`. This patch adds a "switch" to turn off the auto multichannel feature when the API is from cv::dnn::Net (more specifically, `setInput`) and the parameter is of type `Mat`. This patch only leads to changes of three places in `pyopencv_generated_types_content.h`: ```.diff static PyObject* pyopencv_cv_dnn_dnn_Net_setInput(PyObject* self, PyObject* py_args, PyObject* kw) { ... - pyopencv_to_safe(pyobj_blob, blob, ArgInfo("blob", 0)) && + pyopencv_to_safe(pyobj_blob, blob, ArgInfo("blob", 8)) && ... } // I guess we also need to change this as one-channel blob is expected for param static PyObject* pyopencv_cv_dnn_dnn_Net_setParam(PyObject* self, PyObject* py_args, PyObject* kw) { ... - pyopencv_to_safe(pyobj_blob, blob, ArgInfo("blob", 0)) ) + pyopencv_to_safe(pyobj_blob, blob, ArgInfo("blob", 8)) ) ... - pyopencv_to_safe(pyobj_blob, blob, ArgInfo("blob", 0)) ) + pyopencv_to_safe(pyobj_blob, blob, ArgInfo("blob", 8)) ) ... } ``` Others are unchanged, e.g. `dnn_SegmentationModel` and stuff like that. ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
@fengyuentau Can you point me to some instructions on how to build and test the pybindings please? |
@cdeln Check below for instructions.
|
@fengyuentau Thanks. Sorry to bother you about installation matters, please redirect me if there is a better place to get help, I really want to be able to test things! Getting this error when I import
Standing in
I use pyenv for python3, and I install the OpenCV python lib into a fresh virtual env. |
@cdeln Could you post the log when you run |
If you mean
|
Looks like you either did not install
You will have to run a clean configure either way by removing the |
Hmm, some questions
|
No, you dont have to install miniconda. CMake’s find_package has some problems in finding Python headers and libraries if it is virtual environment like pyenv or conda. So you need to manually specify them.
…________________________________
发件人: Carl Dehlin ***@***.***>
发送时间: Tuesday, July 16, 2024 6:19:51 PM
收件人: opencv/opencv ***@***.***>
抄送: Yuantao Feng ***@***.***>; Mention ***@***.***>
主题: Re: [opencv/opencv] ONNX broken for identity function (Issue #25763)
Hmm, some questions
1. Do I have to use miniconda? (I use pyenv currently)
2. Doesn't this line mean that numpy is found? /home/cdeln/.pyenv/versions/default/lib/python3.10/site-packages/numpy/core/include (ver 1.24.3)
―
Reply to this email directly, view it on GitHub<#25763 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AEDL63QJLIYBJECX6HUNJ3TZMTXUPAVCNFSM6AAAAABJIP6RAGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZQGUZTSNBWGY>.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@fengyuentau Is the issue still relevant? Could you post brief status here? |
@asmorkalov Built 4.x on my side, tested with the Python snippet in the issue description and below is the results:
3D problem is solved. The 2D or 1D case is by design on OpenCV 4.x. |
System Information
OpenCV python version: 4.10.0.82
PyTorch version: 2.0.0+cu117
Operating System / Platform: Ubuntu 22.04
Python version: 3.10.6
Detailed description
I have been having some issues with ONNX files lately.
Decided to check that the simplest function of them all works: the identity ...
Here is a script that shows for what input shapes ONNX is broken (0, 1 and 3 dimensional inputs).
I redirect stdout when exporting the ONNX file to make the output more readable.
I suspect that this is the underlying error to #25762
Steps to reproduce
which gives me the following output (format: Dimension, OK/ERROR, PyTorch/OpenCV, SourceShape, TargetShape)
As you can see, it's broken for 0, 1 and 3 dimensional inputs.
Issue submission checklist
The text was updated successfully, but these errors were encountered: