This is the fourth day of my participation in the November Gwen Challenge. Check out the details: The last Gwen Challenge 2021
Hardware and software Environment
- Intel(R) Xeon(R) CPU E5-1607 v4 @ 3.10GHz
- GTX 1070 Ti 32G
- Ubuntu 18.04 64 – bit
- Anaconda with python 3.6
- CUDA 9.0
The preparatory work
If you have previously installed dlib through Conda or PIP, uninstall it first
conda uninstall dlib
pip uninstall dlib
Copy the code
Since dlib is written in C++, compilation needs to use cmake, via apt-get installation
sudo apt-get install build-essential cmake
Copy the code
Install the driver
This part has been said above, the reference xugaoxiang.com/2020/09/24/…
Install the CUDA
Then start the installation cuda, official download address: developer.nvidia.com/cuda-downlo…
Run # Run the installation script sudo./ cudA_10.1.243_418.87.00_linux.runCopy the code
During the installation process, there will be some options to choose according to your actual situation, such as whether to use the built-in CUDA drivers, installation path, whether to install samples, etc. (each version is different).
By default, CUDA is installed in /usr/local and a soft link CUDA is created
Then configure the environment variables and edit the ~/.bashrc file
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
Copy the code
Finally, execute source
source ~/.bashrc
Copy the code
Several important environment variables take effect immediately. Or, reopening Terminal works as well.
Install cudnn
Website developer.nvidia.com/cudnn to download, need to register here, a little bit of a problem. It is important to note that cudNN versions are meant to match CUDA
Tar XVF cudnn-10.1-linux-x64-v7.6.3.36. TGZ sudo cp cuda/include/cudnn*. H /usr/local/cuda-10.1/include sudo cp -a Sudo chmod a+r /usr/local/cuda-10.1/lib64/libcudnn* /usr/local/cuda-10.1/lib64/libcudnn*Copy the code
CUDA support for dlib
Then you can compile the source code
# pull source git clone https://github.com/davisking/dlib.git CD dlib mkdir build CD build increased cmake CUDA option #. -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1 cmake --build . cd .. Py install --yes USE_AVX_INSTRUCTIONS --yes DLIB_USE_CUDACopy the code
Take a look at the terminal output during compilation to see the CUDA-related state
validation
After the installation, let’s verify whether the installation is successful
# Python script import dlib print(dlib.__version__) # Check whether CUDA acceleration print(dlib.dlib_use_cuda) # fetch device number print(dlib.cuda.get_num_devices())Copy the code
The resources
- Github.com/davisking/d…