How can I built DNN module with CUDA Backend?

Hi, I’m working with Jetson nano, using python3.6 for object detection. (tiny YOLOv3)
// OpenCV 4.5.4 CUDA 10.2.3 cuDNN 8.2.1 //

I’m trying to make a human detection application using intel realsense camera. When I run the code, it’s run only on CPU. And the following error occurs. The fps of the image is also very low.

global net_impl.cpp:174 setUpNet DNN module was not built with CUDA backend; switching to CPU

However, when I run the realsense viewer, gpu is used. What should I do?

update: I reinstalled opencv and added opencv_world.so in the same directory with code, but nothing changed. Jetson certainly does not use cuda acceleration in this code.

The realsense viewer use gpu.

Hi,

Please check if you have enabled the configuration when building the OpenCV:

$ cmake \
    -D WITH_CUDA=ON \
    -D WITH_CUDNN=ON \
    -D OPENCV_DNN_CUDA=ON \
    ...

Thanks.

In the article, you may meet @AastaLLL 's github to resolve your troubles.

I have configured the opencv with cmake-gui. And Enabled these options:

cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D EIGEN_INCLUDE_PATH=/usr/include/eigen3 \
-D PYTHON_EXECUTABLE=~/env/bin/python3 \
-D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.2 \
-D OpenCL_LIBRARY=/usr/local/cuda-10.2/lib64/libOpenCL.so \
-D OpenCL_INCLUDE_DIR=/usr/local/cuda-10.2/include/ \
-D WITH_OPENCL=OFF \
-D WITH_CUDA=ON \
-D CUDA_ARCH_BIN=5.3 \
-D CUDA_ARCH_PTX="" \
-D WITH_CUDNN=ON \
-D WITH_CUBLAS=1 \
-D ENABLE_FAST_MATH=1 \
-D CUDA_FAST_MATH=1 \
-D OPENCV_DNN_CUDA=ON \
-D ENABLE_NEON=ON \
-D WITH_QT=OFF \
-D WITH_OPENMP=ON \
-D BUILD_TIFF=ON \
-D WITH_FFMPEG=ON \
-D WITH_GSTREAMER=ON \
-D WITH_TBB=ON \
-D BUILD_TBB=ON \
-D BUILD_TESTS=OFF \
-D WITH_EIGEN=ON \
-D WITH_V4L=ON \
-D WITH_LIBV4L=ON \
-D PYTHON3_EXECUTABLES=/usr/local/bin/python3 \
-D PYTHON3_INCLUDE_DIR=/usr/local/include/python3.6m \
-D PYTHON3_LIB=/usr/lib/aarch64-linux-gnu/libpython3.6m.so \
-D PYTHON3_PACKAGES_PATH=/usr/local/lib/python3.6/site-packages \ 
-D PYTHON3_NUMPY_INCLUDE_DIR=/usr/local/lib/python3.6/site-packages/Cython/Includes  \
-D OPENCV_ENABLE_NONFREE=ON \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D OPENCV_GENERATE_PKGCONFIG=ON \
-D BUILD_OPENCV_WORLD=ON \
-D BUILD_OPENCV_DNN= ON \

-D BUILD_EXAMPLES=ON ..

Also I tried to uninstall opencv with the following command.

$ $ sudo apt-get purge libopencv* python-opencv
$ $ sudo find /usr/local/ -name “opencv” -exec rm {} ;
$ $ sudo apt autoremove -y

But it doesn’t seem to have been deleted completely. In that state, I reinstalled opencv. Did not delete opencv completely affect this issue? How to delete opencv completely?

Hi,

Usually, we remove OpenCV with the following command:

$ sudo apt -y purge *libopencv*

If you have built it from the source, please also check if you have removed the path that links to the package.
For example. remove the path that links to the OpenCV source in LD_LIBRARY_PATH and PYTHONPATH.

Thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.