Hello there,
I am trying to run face_recognition code using OpenCV with CUDA support.
The code I am running is;
for name in images:
image = face_recognition.load_image_file(name)
encoding = face_recognition.face_encodings(image)[0]
known_faces.append(encoding)
known_names.append(name)
complete error that i get is;
RuntimeError Traceback (most recent call last)
/tmp/ipykernel_4348/254179735.py in <module>
8 for name in images:
9 image = face_recognition.load_image_file(name)
---> 10 encoding = face_recognition.face_encodings(image)[0]
11 known_faces.append(encoding)
12 known_names.append(name)
~/.local/lib/python3.10/site-packages/face_recognition/api.py in face_encodings(face_image, known_face_locations, num_jitters, model)
212 """
213 raw_landmarks = _raw_face_landmarks(face_image, known_face_locations, model)
--> 214 return [np.array(face_encoder.compute_face_descriptor(face_image, raw_landmark_set, num_jitters)) for raw_landmark_set in raw_landmarks]
215
216
~/.local/lib/python3.10/site-packages/face_recognition/api.py in <listcomp>(.0)
212 """
213 raw_landmarks = _raw_face_landmarks(face_image, known_face_locations, model)
--> 214 return [np.array(face_encoder.compute_face_descriptor(face_image, raw_landmark_set, num_jitters)) for raw_landmark_set in raw_landmarks]
215
216
RuntimeError: Error while calling cudaOccupancyMaxPotentialBlockSize(&num_blocks,&num_threads,K) in file /tmp/pip-install-tfazu_bm/dlib_65f79a31ba2f4549a39bdef8017ea1ef/dlib/cuda/cuda_utils.h:186. code: 98, reason: invalid device function
I am having NVIDIA GeForce RTX 3060 graphics card with NVIDIA-SMI 525.89.02, CUDA Version 12.0 with cuDNN on
@rakhi.proeffico The error you’re encountering seems to be related to an incompatibility between the CUDA version and the Dlib library compiled with CUDA support. To resolve this issue, you can follow these steps:
Uninstall the current Dlib installation:
pip uninstall dlib
Install the required dependencies for building Dlib:
Make sure that you have the correct CUDA version in your environment. For example, you can set the environment variable CUDA_HOME to the CUDA installation directory:
export CUDA_HOME=/usr/local/cuda-12.0
Note: Replace /usr/local/cuda-12.0 with your actual CUDA installation directory.
This command should output True , which indicates that Dlib is using CUDA.
Now, try running your face_recognition code again. The error should be resolved. If you still encounter any issues, make sure your graphics card drivers, CUDA toolkit, and cuDNN library are properly installed and compatible with each other.
CUDA was found but your compiler failed to compile a simple CUDA program so dlib isn't going to use CUDA.
The output of the failed CUDA test compile is shown below:
-- ***
-- *** Change Dir: /home/proeffico/dlib/build/temp.linux-x86_64-3.10/dlib_build/cuda_test_build
***
*** Run Build Command(s):/usr/bin/gmake -f Makefile && [ 50%] Building NVCC (Device) object CMakeFiles/cuda_test.dir/cuda_test_generated_cuda_test.cu.o
*** nvcc warning : The 'compute_35', 'compute_37', 'compute_50', 'sm_35', 'sm_37' and 'sm_50' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
*** nvcc warning : The 'compute_35', 'compute_37', 'compute_50', 'sm_35', 'sm_37' and 'sm_50' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
*** /usr/include/c++/11/bits/std_function.h:435:145: error: parameter packs not expanded with ‘...’:
*** 435 | function(_Functor&& __f)
*** |
This is the error i have got while building dlib.
And output to import dlib; print(dlib.DLIB_USE_CUDA) is False
Looks like there is a incompatibility between the CUDA version and the C++ version you are using.
Try these steps and let me know if you got it working…
1. Update your CUDA version: Make sure you have the latest CUDA version installed that is compatible with your GPU. You can check the compatibility and download the latest version from the NVIDIA website:https://developer.nvidia.com/cuda-downloads
2. Downgrade your GCC version: There might be an incompatibility between the C++ version (GCC) and the CUDA version. Try downgrading GCC to a version that is compatible with the CUDA version you have installed. You can check the compatibility from the CUDA installation guide:NVIDIA Documentation
To downgrade GCC, you can use the following commands: