Skip to content

Instantly share code, notes, and snippets.

@nguyenhoan1988
Created October 19, 2021 22:05
Show Gist options
  • Save nguyenhoan1988/ed92d58054b985a1b45a521fcf8fa781 to your computer and use it in GitHub Desktop.
Save nguyenhoan1988/ed92d58054b985a1b45a521fcf8fa781 to your computer and use it in GitHub Desktop.
Installing dlib using conda with CUDA enabled

Installing dlib using conda with CUDA enabled

Prerequisite: conda and/or miniconda are already installed

  1. Create a conda environment.
$ conda create -n dlib python=3.8 cmake ipython
  1. Activate the environment.
$ conda activate dlib
  1. Install CUDA and cuDNN with conda using nvidia channel
$ conda install cuda cudnn -c nvidia

Then find the path to the nvcc of this environment. We will use this path for the build step below

$which nvcc
/path/to/your/miniconda3/envs/dlib/bin/
  1. Install dlib. Clone and build dlib from source
$ git clone https://github.com/davisking/dlib.git
$ cd dlib
$ mkdir build
$ cd build
$ cmake .. -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1 -DCUDAToolkit_ROOT=/path/to/your/miniconda3/envs/dlib/bin/
$ cmake --build .
$ cd ..
$ python setup.py install --set DLIB_USE_CUDA=1
  1. Test dlib
(dlib) $ ipython
Python 3.8.12 (default, Oct 12 2021, 13:49:34)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.27.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: import dlib

In [2]: dlib.DLIB_USE_CUDA
Out[2]: True

In [3]: print(dlib.cuda.get_num_devices())
1
@mtalhaubaid
Copy link

mtalhaubaid commented Jun 13, 2023

I got this message after installing.

Installed c:\users\asdf\anaconda3\envs\dlib\lib\site-packages\dlib-19.24.99-py3.8-win-amd64.egg
Processing dependencies for dlib==19.24.99
Finished processing dependencies for dlib==19.24.99

But when try to test dlib it gives this error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\ASDF\anaconda3\envs\dlib\lib\site-packages\dlib-19.24.99-py3.8-win-amd64.egg\dlib\__init__.py", line 19, in <module>
    from _dlib_pybind11 import *
ImportError: DLL load failed while importing _dlib_pybind11: The specified module could not be found.
>>> import dlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\ASDF\anaconda3\envs\dlib\lib\site-packages\dlib-19.24.99-py3.8-win-amd64.egg\dlib\__init__.py", line 19, in <module>
    from _dlib_pybind11 import *
ImportError: DLL load failed while importing _dlib_pybind11: The specified module could not be found.
>>> import dlib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\ASDF\anaconda3\envs\dlib\lib\site-packages\dlib-19.24.99-py3.8-win-amd64.egg\dlib\__init__.py", line 19, in <module>
    from _dlib_pybind11 import *
ImportError: DLL load failed while importing _dlib_pybind11: The specified module could not be found.

@DUDUKorte
Copy link

getting this error:

Could not load library libcudnn_cnn_train.so.8. Error: /home/ankit/anaconda3/envs/dlib/bin/../lib/libcudnn_ops_train.so.8: undefined symbol: _Z22cudnnGenericOpTensorNdILi3EE13cudnnStatus_tP12cudnnContext16cudnnGenericOp_t21cudnnNanPropagation_tPKdPKvPK17cudnnTensorStructS8_S8_SB_S8_S8

i got the exactly same error, anyone knows how to fix it???

@bwajster
Copy link

Does this work on Ubuntu 18.04? Also, can you share the link to install conda?

@mtalhaubaid
Copy link

@bwajster97 I think It should work on ubuntu as well

@lingster
Copy link

lingster commented Feb 8, 2024

if you are running on arch linux and you are getting these errors try temporarily downgrading your cc/gcc compilers like this:

export CXX="/usr/bin/g++-12"
export CC="/usr/bin/gcc-12"

or wherever the correct path you have installed the previous versions of the compiler.

@s2485523800
Copy link

Thanks a lot.
maybe somebody installed cudnn but dlib said not found, you can use " set CMAKE_PREFIX_PATH=path/to/cudnn"( in conda is /Library) to fix this problem

@huhreenee
Copy link

Hi @s2485523800, I am facing this issue, unfortunately, I am not able to set CMAKE_PREFIX_PATH correctly. Could you please help?

@s2485523800
Copy link

Hi @s2485523800, I am facing this issue, unfortunately, I am not able to set CMAKE_PREFIX_PATH correctly. Could you please help?

maybe you can take a photo about your conda env path,and conda list

@semajbaker
Copy link

thanks. Worked for me too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment