3

I am able to successfully install Dlib with CUDA support in Windows 10 but getting an error during "import dlib" in my python code of computer vision project.

Environment: Windows 10, Python 3.7.6 (Anaconda), CUDA 11, CuDNN 10.2

Error Message:

>>> import dlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ProgramData\Anaconda3\lib\site-packages\dlib-19.20.99-py3.7-win-amd64.egg\dlib\__init__.py", line 12, in <module>
    from _dlib_pybind11 import *
ImportError: DLL load failed: The specified module could not be found.
talonmies
  • 70,661
  • 34
  • 192
  • 269
Harsh
  • 81
  • 1
  • 6

5 Answers5

4

This can be solved by copying the cudnn64_7.dll (available here: https://developer.nvidia.com/cudnn) into the %CUDA_PATH%/bin directory (probably something like this: C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin)

  • Are you sure that cannot be done by some installation or update procedures? Downloading a big pack of stuff and then cherry-picking one lib to place it manually to a system folder... I hoped we don't usually need that since 90's – Gryphon Jun 16 '20 at 12:07
  • I already copied cuDNN library to bin folder as you suggested. (Gryphon is correct. Why NVIDIA installation does not copy to this folder automatically) – Harsh Jun 17 '20 at 22:10
3

If you are using Anaconda, uninstall dlib and reinstall dlib. In anaconda command prompt, type

 pip uninstall dlib

After successfully uninstalling, type

 pip install dlib

It helped me fix the problem.

Aditya R
  • 31
  • 2
  • Let me add, if you use ```RUN --mount=type=cache,target=/root/.cache/pip pip install dlib``` in a Dockerfile, change this line to install without cache – zetyquickly Jan 08 '23 at 23:44
  • Let me add, if this doesn't work again on uninstalling and installing then again first uninstall and install it with this command `pip install --no-cache-dir dlib` – Muhammad Shifa Jun 24 '23 at 10:13
2

I am able to find and fix this issue. CUDA 11 installation wasn't able to add few of the directories into the PATH environment variable (Windows 10). It was truncated due to the max length of 2048 characters. I have removed a few of the unused software paths from PATH value and after reinstallation, dlib 19.20 is working with CUDA 11 now.

I created an issue on DLIB Github under the following link which has more information regarding error logs and snapshots for this issue. https://github.com/davisking/dlib/issues/2097

Harsh
  • 81
  • 1
  • 6
2

In my environment, the problem was due to an error somewhere in the build process that resulted code to load CuDNN dynamic libraries not being included in the generated file dlib/__init__.py despite having no build error. In my case the file always included this strange block of code:

if 'OFF' == 'ON':
    add_lib_to_dll_path('cudnn-NOTFOUND')
    add_lib_to_dll_path('C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.5/lib/x64/cudart.lib')

The second line's cudnn-NOTFOUND gave a clue of what happened with my build.

As I followed instructions on this page, copying all the binaries and include files to the right places within the CUDA directory, I only needed to modify the code to (similar to what Epic Chen's answer suggests but I got rid of the if clause and the bad code line):

add_lib_to_dll_path('C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.5/lib/x64/cudart.lib')

That workaround fixed the problem for me.

My configuration is CUDA 11.5, CuDNN 8.3.1.22, dlib compiled using Visual Studio 2019. The environment variable CMAKE_PREFIX_PATH to the CuDNN directory to get the compiler to find the include files and libraries.

Giao Vu
  • 71
  • 1
  • 3
0

Try to check the __init__.py file which the error message indicate as below. Your path is not the same as me.

enter image description here

In the __init__.py file, the if statement should be 'ON' == 'ON'

enter image description here

Besides, the following library paths must be correct. Your version may not be the same as me.

enter image description here

Epic Chen
  • 1,282
  • 12
  • 17