DNN module was not built with CUDA backend

  • OpenCV => 4.5.2
  • Operating System / Platform => Ubuntu 20.04
  • Compiler => Visual Studio Code (cmake)
  • Cuda Version => 11.2
  • GPU => GTX 1660 TI
  • CPU => Ryzen 5 2600
  • GPU ARCH => 7.5
  • Cudnn Version => 8.2.1

I have built OpenCV over 10 times, and even went as far as to install the OS 5 times (This was to get a new fresh install of Linux to erase any mistakes I made), I have been on this problem for over a week, followed three installation guides on how to get OpenCV with Cuda support on DNN.
Here are the step by step guilds I followed.

I have tried cuda 10.1, 10.2, 11, 11.2 and 11.4 to no avail. I have tried different gpu arch and even build opencv with ever single arch at once yesterday, but I still get the same error after all of this.
Here is the error I am trying to solve:

[ WARN:0] global …/modules/dnn/src/dnn.cpp (1363) setUpNet DNN module was not built with CUDA backend; switching to CPU

Solved!
Previous cmake command:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D ENABLE_FAST_MATH=ON -D CUDA_FAST_MATH=ON -D WITH_CUBLAS=ON -D WITH_CUDA=ON -D CUDA_ARCH_BIN=7.5 -D BUILD_opencv_cudacodec=OFF -D WITH_CUDNN=ON -D OPENCV_DNN_CUDA=ON -D WITH_V4L=ON -D WITH_QT=OFF -D WITH_OPENGL=ON -D WITH_GSTREAMER=ON -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_PC_FILE_NAME=opencv.pc -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_PYTHON3_INSTALL_PATH=~/.virtualenvs/cv/lib/python3.8/site-packages -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python -D OPENCV_EXTRA_MODULES_PATH=~/Downloads/opencv_contrib-4.5.2/modules -D INSTALL_PYTHON_EXAMPLES=OFF -D INSTALL_C_EXAMPLES=OFF -D BUILD_EXAMPLES=OFF -D OPENCV_GENERATE_PKGCONFIG=ON -D OpenCV_DIR=~/Downloads/opencv-4.5.2/build ..

The result:
pkg-config --modversion opencv4
4.2.0

pkg-config --modversion opencv
4.5.2

The one that I used to fix my issue:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D ENABLE_FAST_MATH=ON -D CUDA_FAST_MATH=ON -D WITH_CUBLAS=ON -D WITH_CUDA=ON -D CUDA_ARCH_BIN=7.5 -D BUILD_opencv_cudacodec=OFF -D WITH_CUDNN=ON -D OPENCV_DNN_CUDA=ON -D WITH_V4L=ON -D WITH_QT=OFF -D WITH_OPENGL=ON -D WITH_GSTREAMER=ON -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_PC_FILE_NAME=opencv4.pc -D OPENCV_ENABLE_NONFREE=ON -D OPENCV_PYTHON3_INSTALL_PATH=~/.virtualenvs/cv/lib/python3.8/site-packages -D PYTHON_EXECUTABLE=~/.virtualenvs/cv/bin/python -D OPENCV_EXTRA_MODULES_PATH=~/Downloads/opencv_contrib-4.5.2/modules -D INSTALL_PYTHON_EXAMPLES=OFF -D INSTALL_C_EXAMPLES=OFF -D BUILD_EXAMPLES=OFF -D OPENCV_GENERATE_PKGCONFIG=ON -D OpenCV_DIR=~/Downloads/opencv-4.5.2/build ..

The result:
pkg-config --modversion opencv4
4.5.2

pkg-config --modversion opencv
4.5.2

DNN with Cuda now works. Thanks Devs for making OpenCV!

i closed your other question about it, please spare us duplicates in the future, thank you.

1 Like