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

ONNX broken for identity function #25763

Open
4 tasks done
cdeln opened this issue Jun 13, 2024 · 18 comments
Open
4 tasks done

ONNX broken for identity function #25763

cdeln opened this issue Jun 13, 2024 · 18 comments
Assignees
Labels
bug category: dnn (onnx) ONNX suport issues in DNN module category: dnn
Milestone

Comments

@cdeln
Copy link

cdeln commented Jun 13, 2024

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

import torch
import cv2 as cv
from contextlib import redirect_stdout

class Identity(torch.nn.Module):

    def __init__(self):
        super().__init__()

    def forward(self, X):
        return X

model = Identity()
shape = (2,3,5,7,11,13,17,19)

for i in range(1 + len(shape)):
    X = torch.zeros(shape[:i])
    with open('/dev/null', 'w') as f:
        with redirect_stdout(f):
            torch.onnx.export(model, X, '/tmp/model.onnx', output_names=['Y'])

    Y = model(X)
    ok = X.shape == Y.shape
    print('OK   ' if ok else 'ERROR', 'PyTorch', tuple(X.shape), '->', tuple(Y.shape))

    net = cv.dnn.readNetFromONNX('/tmp/model.onnx')
    X = X.numpy()
    net.setInput(X)

    Y = net.forward(['Y'])[0]
    ok = X.shape == Y.shape
    print('OK   ' if ok else 'ERROR', 'OpenCV ', X.shape, '->', Y.shape)

which gives me the following output (format: Dimension, OK/ERROR, PyTorch/OpenCV, SourceShape, TargetShape)

0 OK    PyTorch () -> ()
0 ERROR OpenCV  () -> (1, 1)
1 OK    PyTorch (2,) -> (2,)
1 ERROR OpenCV  (2,) -> (2, 1)
2 OK    PyTorch (2, 3) -> (2, 3)
2 OK    OpenCV  (2, 3) -> (2, 3)
3 OK    PyTorch (2, 3, 5) -> (2, 3, 5)
3 ERROR OpenCV  (2, 3, 5) -> (2, 3)
4 OK    PyTorch (2, 3, 5, 7) -> (2, 3, 5, 7)
4 OK    OpenCV  (2, 3, 5, 7) -> (2, 3, 5, 7)
5 OK    PyTorch (2, 3, 5, 7, 11) -> (2, 3, 5, 7, 11)
5 OK    OpenCV  (2, 3, 5, 7, 11) -> (2, 3, 5, 7, 11)
6 OK    PyTorch (2, 3, 5, 7, 11, 13) -> (2, 3, 5, 7, 11, 13)
6 OK    OpenCV  (2, 3, 5, 7, 11, 13) -> (2, 3, 5, 7, 11, 13)
7 OK    PyTorch (2, 3, 5, 7, 11, 13, 17) -> (2, 3, 5, 7, 11, 13, 17)
7 OK    OpenCV  (2, 3, 5, 7, 11, 13, 17) -> (2, 3, 5, 7, 11, 13, 17)
8 OK    PyTorch (2, 3, 5, 7, 11, 13, 17, 19) -> (2, 3, 5, 7, 11, 13, 17, 19)
8 OK    OpenCV  (2, 3, 5, 7, 11, 13, 17, 19) -> (2, 3, 5, 7, 11, 13, 17, 19)

As you can see, it's broken for 0, 1 and 3 dimensional inputs.

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
Copy link
Contributor

@Abdurrahheem could you take a look?

@asmorkalov asmorkalov added the category: dnn (onnx) ONNX suport issues in DNN module label Jun 14, 2024
@fengyuentau
Copy link
Member

fengyuentau commented Jun 17, 2024

Error cases are:

0 ERROR OpenCV  () -> (1, 1)
1 ERROR OpenCV  (2,) -> (2, 1)
3 ERROR OpenCV  (2, 3, 5) -> (2, 3)

Let me explain one by one.

  1. 0 ERROR OpenCV () -> (1, 1): OpenCV Mat does not support 0d, 1d cases; that is to say, when a 0d/1d tensor is loaded into a Mat, it is converted to a Mat of shape (1, 1).
  2. 1 ERROR OpenCV (2,) -> (2, 1): Similar above. In case of 1d tensor of shape (n,), it is Mat of shape (n, 1) (so it breaks the rule of broadcasting) when converted.
  3. 3 ERROR OpenCV (2, 3, 5) -> (2, 3): In the OpenCV Python interface, a three dimensional (a, b, c) tensor is loaded into a Mat of shape (a, b) with channel equals to c. More details see dnn: getting wrong input shape if using python interfaces #23242. This is a legacy problem which should be solved in 5.x I think.

@cdeln
Copy link
Author

cdeln commented Jun 17, 2024

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.

@fengyuentau
Copy link
Member

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.

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.

@cdeln
Copy link
Author

cdeln commented Jun 17, 2024

@fengyuentau Ok good point. Is the fix for 3d input also not backwards compatible or can it be included in 4.x?

@fengyuentau
Copy link
Member

@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.

asmorkalov pushed a commit that referenced this issue Jul 4, 2024
…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
Copy link
Member

@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.

@cdeln 3d input issue has been solved in #25810.

@cdeln
Copy link
Author

cdeln commented Jul 4, 2024

@fengyuentau I will try out asap :)

vrabaud pushed a commit to vrabaud/opencv that referenced this issue Jul 4, 2024
…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
@cdeln
Copy link
Author

cdeln commented Jul 12, 2024

@fengyuentau Can you point me to some instructions on how to build and test the pybindings please?

@fengyuentau
Copy link
Member

@cdeln Check below for instructions.

# Get opencv
git clone https://github.com/opencv/opencv

# Configure opencv
cmake -B build \
      -S opencv \
      -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=build/install \
      -D BUILD_opencv_python2=OFF \
      -D BUILD_opencv_python3=ON \
      -D -DPYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3
# If you use conda, add the following two options as well
#      -D PYTHON3_EXECUTABLE=/absolute/path/to/python \
#      -D PYTHON3_INCLUDE=/absolute/path/to/Python.h/location \
#      -D PYTHON3_LIBRARIES=/absolute/path/to/libpython/location
# Example: 
#      -D PYTHON3_EXECUTABLE=/Workspace/miniconda3/bin/python \
#      -D PYTHON3_INCLUDE=/Workspace/miniconda3/include/python3.10 \
#      -D PYTHON3_LIBRARIES=/Workspace/miniconda3/lib \

# Build opencv
cmake --build build --target install -j8

# Install python package. Make sure you uninstall opencv packages beforehand.
python3 -m pip install ./build/python_loader

@cdeln
Copy link
Author

cdeln commented Jul 16, 2024

@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 cv2, what am I missing?

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/cdeln/src/opencv/lib/python3.10/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/home/cdeln/src/opencv/lib/python3.10/site-packages/cv2/__init__.py", line 112, in bootstrap
    load_first_config([
  File "/home/cdeln/src/opencv/lib/python3.10/site-packages/cv2/__init__.py", line 109, in load_first_config
    raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames))
ImportError: OpenCV loader: missing configuration file: ['config-3.10.py', 'config-3.py']. Check OpenCV installation.

Standing in /home/cdeln/src, I configured it like this

cmake -B build \
      -S opencv \
      -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=build/install \
      -D BUILD_opencv_python2=OFF \
      -D BUILD_opencv_python3=ON \
      -DPYTHON_DEFAULT_EXECUTABLE=$(which python3)
      -D PYTHON3_EXECUTABLE=$(which python3)

I use pyenv for python3, and I install the OpenCV python lib into a fresh virtual env.

@fengyuentau
Copy link
Member

@cdeln Could you post the log when you run cmake -B .. command?

@cdeln
Copy link
Author

cdeln commented Jul 16, 2024

If you mean cmake -B build -S opencv (assuming I stand in /home/cdeln/src, cloned OpenCV into opencv and configuring into sibling directory build), then output is

-- Detected processor: x86_64
-- Looking for ccache - found (/usr/bin/ccache)
Cleaning INTERNAL cached variable: WEBP_LIBRARY
Cleaning INTERNAL cached variable: WEBP_INCLUDE_DIR
-- Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
-- OpenJPEG: VERSION = 2.5.0, BUILD = opencv-4.10.0-dev-openjp2-2.5.0
-- OpenJPEG libraries will be built from sources: libopenjp2 (version "2.5.0")
-- Found OpenEXR: /usr/lib/x86_64-linux-gnu/libIlmImf-2_5.so
-- libva: missing va.h header (VA_INCLUDE_DIR)
-- found Intel IPP (ICV version): 2021.11.0 [2021.11.0]
-- at: /home/cdeln/src/build/3rdparty/ippicv/ippicv_lnx/icv
-- found Intel IPP Integration Wrappers sources: 2021.11.0
-- at: /home/cdeln/src/build/3rdparty/ippicv/ippicv_lnx/iw
-- Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
-- Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
-- Could NOT find Atlas (missing: Atlas_CLAPACK_INCLUDE_DIR) 
-- Could NOT find JNI (missing: AWT) 
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
-- Checking for module 'gtk+-3.0'
--   No package 'gtk+-3.0' found
-- Checking for module 'libavresample'
--   No package 'libavresample' found
-- Checking for module 'gstreamer-base-1.0'
--   No package 'gstreamer-base-1.0' found
-- Checking for module 'gstreamer-app-1.0'
--   No package 'gstreamer-app-1.0' found
-- Checking for module 'gstreamer-riff-1.0'
--   No package 'gstreamer-riff-1.0' found
-- Checking for module 'gstreamer-pbutils-1.0'
--   No package 'gstreamer-pbutils-1.0' found
-- Checking for module 'gstreamer-video-1.0'
--   No package 'gstreamer-video-1.0' found
-- Checking for module 'gstreamer-audio-1.0'
--   No package 'gstreamer-audio-1.0' found
-- Allocator metrics storage type: 'long long'
-- Excluding from source files list: <BUILD>/modules/core/test/test_intrin256.lasx.cpp
-- Excluding from source files list: modules/imgproc/src/imgwarp.lasx.cpp
-- Excluding from source files list: modules/imgproc/src/resize.lasx.cpp
-- Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': /home/cdeln/src/opencv/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
-- opencv_dnn: filter out cuda4dnn source code
-- Excluding from source files list: modules/dnn/src/layers/cpu_kernels/conv_winograd_f63.neon.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.rvv.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.lasx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.rvv.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.lasx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_block.neon.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_block.neon_fp16.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_depthwise.rvv.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_depthwise.lasx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/conv_winograd_f63.neon_fp16.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/fast_gemm_kernels.neon.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/cpu_kernels/fast_gemm_kernels.lasx.cpp
-- highgui: using builtin backend: GTK2
-- Found 'misc' Python modules from /home/cdeln/src/opencv/modules/python/package/extra_modules
-- Found 'mat_wrapper;utils' Python modules from /home/cdeln/src/opencv/modules/core/misc/python/package
-- Found 'gapi' Python modules from /home/cdeln/src/opencv/modules/gapi/misc/python/package
-- 
-- General configuration for OpenCV 4.10.0-dev =====================================
--   Version control:               4.10.0-117-gc6ace77e21
-- 
--   Platform:
--     Timestamp:                   2024-07-12T12:07:11Z
--     Host:                        Linux 6.5.0-41-generic x86_64
--     CMake:                       3.26.3
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/gmake
--     Configuration:               RELEASE
-- 
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3
--       requested:                 SSE3
--     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
--       SSE4_1 (18 files):         + SSSE3 SSE4_1
--       SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
--       FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
--       AVX (9 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
--       AVX2 (38 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
--       AVX512_SKX (8 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                /usr/bin/c++  (ver 11.4.0)
--     C++ flags (Release):         -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined  
--     Linker flags (Debug):        -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined  
--     ccache:                      YES
--     Precompiled headers:         NO
--     Extra dependencies:          dl m pthread rt
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo stitching ts video videoio
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 java python2 python3
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
-- 
--   GUI:                           GTK2
--     GTK+:                        YES (ver 2.24.33)
--       GThread :                  YES (ver 2.72.4)
--       GtkGlExt:                  NO
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
--     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.37)
--     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.3.0)
--     JPEG 2000:                   build (ver 2.5.0)
--     OpenEXR:                     /usr/lib/x86_64-linux-gnu/libImath-2_5.so /usr/lib/x86_64-linux-gnu/libIlmImf-2_5.so /usr/lib/x86_64-linux-gnu/libIex-2_5.so /usr/lib/x86_64-linux-gnu/libHalf-2_5.so /usr/lib/x86_64-linux-gnu/libIlmThread-2_5.so (ver 2_5)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
-- 
--   Video I/O:
--     DC1394:                      YES (2.2.6)
--     FFMPEG:                      YES
--       avcodec:                   YES (58.134.100)
--       avformat:                  YES (58.76.100)
--       avutil:                    YES (56.70.100)
--       swscale:                   YES (5.9.100)
--       avresample:                NO
--     GStreamer:                   NO
--     v4l/v4l2:                    YES (linux/videodev2.h)
-- 
--   Parallel framework:            pthreads
-- 
--   Trace:                         YES (with Intel ITT)
-- 
--   Other third-party libraries:
--     Intel IPP:                   2021.11.0 [2021.11.0]
--            at:                   /home/cdeln/src/build/3rdparty/ippicv/ippicv_lnx/icv
--     Intel IPP IW:                sources (2021.11.0)
--               at:                /home/cdeln/src/build/3rdparty/ippicv/ippicv_lnx/iw
--     VA:                          NO
--     Lapack:                      NO
--     Eigen:                       YES (ver 3.4.0)
--     Custom HAL:                  NO
--     Protobuf:                    build (3.19.1)
--     Flatbuffers:                 builtin/3rdparty (23.5.9)
-- 
--   OpenCL:                        YES (no extra features)
--     Include path:                /home/cdeln/src/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
-- 
--   Python 3:
--     Interpreter:                 /home/cdeln/.pyenv/versions/default/bin/python3 (ver 3.10.6)
--     Libraries:                   NO
--     Limited API:                 NO
--     numpy:                       /home/cdeln/.pyenv/versions/default/lib/python3.10/site-packages/numpy/core/include (ver 1.24.3)
--     install path:                -
-- 
--   Python (for build):            /home/cdeln/src/opencv/bin/python3
-- 
--   Java:                          
--     ant:                         NO
--     Java:                        YES (ver 17.0.11)
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
-- 
--   Install to:                    /home/cdeln/src/build/install
-- -----------------------------------------------------------------
-- 
-- Configuring done (0.8s)
-- Generating done (0.2s)
-- Build files have been written to: /home/cdeln/src/build

@fengyuentau
Copy link
Member

fengyuentau commented Jul 16, 2024

--   Python 3:
--     Interpreter:                 /home/cdeln/.pyenv/versions/default/bin/python3 (ver 3.10.6)
--     Libraries:                   NO
--     Limited API:                 NO
--     numpy:                       /home/cdeln/.pyenv/versions/default/lib/python3.10/site-packages/numpy/core/include (ver 1.24.3)
--     install path:                -

Looks like you either did not install numpy or need using the following options:

# Example: 
#      -D PYTHON3_EXECUTABLE=/Workspace/miniconda3/bin/python \
#      -D PYTHON3_INCLUDE=/Workspace/miniconda3/include/python3.10 \
#      -D PYTHON3_LIBRARIES=/Workspace/miniconda3/lib \

You will have to run a clean configure either way by removing the build.

@cdeln
Copy link
Author

cdeln commented Jul 16, 2024

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)

@fengyuentau
Copy link
Member

fengyuentau commented Jul 16, 2024 via email

@asmorkalov
Copy link
Contributor

@fengyuentau Is the issue still relevant? Could you post brief status here?

@fengyuentau
Copy link
Member

fengyuentau commented Dec 25, 2024

@asmorkalov Built 4.x on my side, tested with the Python snippet in the issue description and below is the results:

OK    PyTorch () -> ()
ERROR OpenCV  () -> (1, 1)
OK    PyTorch (2,) -> (2,)
ERROR OpenCV  (2,) -> (2, 1)
OK    PyTorch (2, 3) -> (2, 3)
OK    OpenCV  (2, 3) -> (2, 3)
OK    PyTorch (2, 3, 5) -> (2, 3, 5)
OK    OpenCV  (2, 3, 5) -> (2, 3, 5)
OK    PyTorch (2, 3, 5, 7) -> (2, 3, 5, 7)
OK    OpenCV  (2, 3, 5, 7) -> (2, 3, 5, 7)
OK    PyTorch (2, 3, 5, 7, 11) -> (2, 3, 5, 7, 11)
OK    OpenCV  (2, 3, 5, 7, 11) -> (2, 3, 5, 7, 11)
OK    PyTorch (2, 3, 5, 7, 11, 13) -> (2, 3, 5, 7, 11, 13)
OK    OpenCV  (2, 3, 5, 7, 11, 13) -> (2, 3, 5, 7, 11, 13)
OK    PyTorch (2, 3, 5, 7, 11, 13, 17) -> (2, 3, 5, 7, 11, 13, 17)
OK    OpenCV  (2, 3, 5, 7, 11, 13, 17) -> (2, 3, 5, 7, 11, 13, 17)
OK    PyTorch (2, 3, 5, 7, 11, 13, 17, 19) -> (2, 3, 5, 7, 11, 13, 17, 19)
OK    OpenCV  (2, 3, 5, 7, 11, 13, 17, 19) -> (2, 3, 5, 7, 11, 13, 17, 19)

3D problem is solved. The 2D or 1D case is by design on OpenCV 4.x.

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

No branches or pull requests

5 participants