[PYTHON] How to install DLIB with 2020 / CUDA enabled

Overview

I succeeded in installing dlib with CUDA and cuDNN enabled, so I recorded it as a memorandum. The installation method differs depending on the version of dlib, and CUDA may not be enabled even if you follow the article on the net. The installation method changes every time dlib is updated, so if it doesn't work, check dlib official How to compile. The following procedure is the installation method as of July 6, 2020

environment

Installation

Install CUDA, cuDNN

If you haven't installed both CUDA and cuDNN yet, install the two first.

##First install CUDA
$ sudo apt update -y
$ sudo apt upgrade -y
$ wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
$ sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
$ wget http://developer.download.nvidia.com/compute/cuda/10.2/Prod/local_installers/cuda-repo-ubuntu1804-10-2-local-10.2.89-440.33.01_1.0-1_amd64.deb
$ sudo apt-key add /var/cuda-repo-10-2-local-10.2.89-440.33.01/7fa2af80.pub
$ sudo apt-get -y update
$ sudo apt-get -y install cuda
$ echo "export PATH=/usr/local/cuda-10.2/bin${PATH:+:${PATH}}" >> ~/.bashrc
$ echo "export LD_LIBRARY_PATH=/usr/local/cuda-10.2/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}" >> ~/.bashrc

Reboot once here After starting, confirm that CUDA is installed with the following command

$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:24:38_PDT_2019
Cuda compilation tools, release 10.2, V10.2.89

If you can confirm, CUDA installation is complete Then install cuDNN

#cuDNN installation
$ wget https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/libcudnn7_7.6.5.32-1+cuda10.2_amd64.deb
$ wget https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/libcudnn7-dev_7.6.5.32-1+cuda10.2_amd64.deb
$ sudo dpkg -i libcudnn7_7.6.5.32-1+cuda10.2_amd64.deb
$ sudo dpkg -i libcudnn7-dev_7.6.5.32-1+cuda10.2_amd64.deb

Reboot once here This completes the installation of CUDA and cuDNN.

Install required cmake in advance

$ sudo apt -y install cmake

Download dlib

Check dlib official and download the latest source code

$ wget http://dlib.net/files/dlib-19.20.tar.bz2
$ tar -jxvf dlib-19.20.tar.bz2

dlib installation

Install using setup.py in the dlib-19.20 folder dlib-19.20 does not need to be installed using the make command Also, there are many articles out there that you need to add the `` `-yes USE_AVX_INSTRUCTIONS --yes DLIB_USE_CUDA``` option. In v.19.20, the yes option is obsolete and is enabled by default, so you no longer need to add the option.

$ cd dlib-19.20
$ python3 setup.py install

Make sure CUDA and cuDNN are enabled when setup.py is run. If the following message is not displayed, CUDA and cuDNN will be installed with disabled.

-- Found CUDA: /usr/local/cuda-10.2 (found suitable version "10.2", minimum required is "7.5") 
-- Looking for cuDNN install...
-- Found cuDNN: /usr/lib/x86_64-linux-gnu/libcudnn.so
-- Building a CUDA test project to see if your compiler is compatible with CUDA...
-- Checking if you have the right version of cuDNN installed.
-- Enabling CUDA support for dlib.  DLIB WILL USE CUDA

I also get a warning `` `No BLAS library found so using dlib's built in BLAS```, which can be ignored (maybe)

Verification

Start python in interactive mode, and if DLIB_USE_CUDA is True, it ends successfully If it is False here, CUDA and cuDNN are not applied and are installed.

$ python3
Python 3.7.6 (default, Jan  8 2020, 19:59:22) 
Type "help", "copyright", "credits" or "license" for more information.
>>> import dlib
>>> dlib.DLIB_USE_CUDA
True

Recommended Posts

How to install DLIB with 2020 / CUDA enabled
How to install python-pip with ubuntu20.04LTS
How to install CUDA and nvidia-driver
How to install mysql-connector with pip3
How to install Anaconda with pyenv
How to install zsh (with .zshrc customization)
How to install python3 with docker centos
How to install Python
How to install pip
How to install archlinux
How to install python
How to install BayesOpt
How to install Nbextensions
How to install Prover9
How to install OpenGM on OSX with macports
[2020.8 latest] How to install Python
How to install Python [Windows]
Tabpy 1.0 (2020-01 version) How to install
How to install caffe on OS X with macports
How to update with SQLAlchemy?
How to cast with Theano
How to install mkl numpy
How to Alter with SQLAlchemy?
How to separate strings with','
How to install Pelican blog
How to RDP with Fedora31
How to Delete with SQLAlchemy?
How to install NPI + send a message to line with python
How to install Python2.7 python3.5 with pyenv (on RHEL5 CentOS5) (2016 Nov)
How to install Theano on Mac OS X with homebrew
How to install python using anaconda
Python: How to use async with
How to install mysql-connector-python on mac
How to install and use Tesseract-OCR
What to do with Magics install
How to use virtualenv with PowerShell
How to deal with imbalanced data
How to install graph-tool on macOS
How to install wkhtmltopdf (Amazon Linux2)
How to deal with imbalanced data
How to install VMware-Tools on Linux
How to install pycrypto on Windows
How to install OpenCV on Mac
How to install MBDyn (Linux Ubuntu)
How to install PyPy on CentOS
How to get started with Scrapy
Easy to install pyspark with conda
How to get started with Python
How to install TensorFlow on CentOS 7
How to deal with DistributionNotFound errors
How to install and configure blackbird
How to get started with Django
How to install and use Graphviz
Unable to install Python with pyenv
How to Data Augmentation with PyTorch
How to use FTP with Python
How to calculate date with python
How to install Maven on CentOS
How to INNER JOIN with SQLAlchemy
How to install Go on Ubuntu
How to install music 21 on windows