Dlib python install ubuntu

Install dlib library in Ubuntu

You can have python lib in two different ways. 1) you can compile it from source or 2) you can install it directly from pip. Issue with pip install is, you cannot use CUDA library with dlib. For that, first you need is to install CUDA on you local machine. Then, you need to compile dlib library from source.

3. Compile dlib from source.

wget http://dlib.net/files/dlib-19.9.tar.bz2 tar xvf dlib-19.9.tar.bz2 cd dlib-19.9/ mkdir build cd build cmake .. cmake --build . --config Release sudo make install sudo ldconfig cd .. pkg-config --libs --cflags dlib-1

4. Install virtual environment for python2 and python3

Virtual environments in python is a great way to maintain different settings for each project. This way one can avoid package conflicts.

# install virtualenv for python 2 sudo pip2 install virtualenv virtualenvwrapper # install virtualenv for python 3 sudo pip3 install virtualenv virtualenvwrapper # update bashrc so that mkvirtualenv, workon and deactivate commands are available in terminal echo "# Python's Virtual Environment Wrapper" >> ~/.bashrc echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc source ~/.bashrc

5. Installing dlib for python 2

# create virtual environment for machine learning mkvirtualenv ml-py2 -p python2 workon ml-py2 # now install python libraries within this virtual environment pip install numpy scipy matplotlib scikit-image scikit-learn ipython # if you want to install dlib from pip pip install dlib # else if you have compiled from source move to dlib's root directory cd dlib-19.9 python setup.py install # clean up (this step is required if you want to build dlib for both Python2 and Python3) rm -rf dist rm -rf tools/python/build rm python_examples/dlib.so # quit virtual environment deactivate

5. dlib library in Python 3

# create virtual environment mkvirtualenv ml-py3 -p python3 workon ml-py3 # now install python libraries within this virtual environment pip install numpy scipy matplotlib scikit-image scikit-learn ipython # if you want to install dlib from pip pip install dlib # else if you have compiled from source move to dlib's root directory cd dlib-19.9 python setup.py install # quit virtual environment deactivate

Congratulations! yours Python Dlib library is successfully installed. You can start using dlib for variety of purposes. Check Out:

Leave a comment in case of any query. I will be happy to help.

Читайте также:  Шаблон панели администратора html

Please subscribe to check out my future posts. Cheers!

Источник

Install Dlib on Ubuntu

Install Dlib on Ubuntu

In this post, we will provide step by step instructions on how to install Dlib on Ubuntu.

Step 1: Install OS libraries

sudo apt-get install build-essential cmake pkg-config sudo apt-get install libx11-dev libatlas-base-dev sudo apt-get install libgtk-3-dev libboost-python-dev

Step 2: Install Python libraries

sudo apt-get install python-dev python-pip python3-dev python3-pip sudo -H pip2 install -U pip numpy sudo -H pip3 install -U pip numpy

We will use Virtual Environment to install Python libraries. It is generally a good practice in order to separate your project environment and global environment.

# Install virtual environment sudo pip2 install virtualenv virtualenvwrapper sudo pip3 install virtualenv virtualenvwrapper echo "# Virtual Environment Wrapper" >> ~/.bashrc echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc source ~/.bashrc ############ For Python 2 ############ # create virtual environment mkvirtualenv facecourse-py2 -p python2 workon facecourse-py2 # now install python libraries within this virtual environment pip install numpy scipy matplotlib scikit-image scikit-learn ipython # quit virtual environment deactivate ###################################### ############ For Python 3 ############ # create virtual environment mkvirtualenv facecourse-py3 -p python3 workon facecourse-py3 # now install python libraries within this virtual environment pip install numpy scipy matplotlib scikit-image scikit-learn ipython # quit virtual environment deactivate ######################################

Master Generative AI for CV

Get expert guidance, insider tips & tricks. Create stunning images, learn to fine tune diffusion models, advanced Image editing techniques like In-Painting, Instruct Pix2Pix and many more

Step 3: Compile DLib

Step 3.1: Compile C++ binary

Davis King, creator of Dlib, recommends using CMake for using Dlib in your code.
But if you want to use Dlib as a library follow these steps:

wget http://dlib.net/files/dlib-19.6.tar.bz2 tar xvf dlib-19.6.tar.bz2 cd dlib-19.6/ mkdir build cd build cmake .. cmake --build . --config Release sudo make install sudo ldconfig cd ..

Now you can use pkg-config to provide path to Dlib’s include directory and link Dlib library file.

pkg-config --libs --cflags dlib-1

Step 3.2: Compile Python module

Activate Python virtual environment.

############ For Python 2 ############ workon facecourse-py2 ############ For Python 3 ############ workon facecourse-py3

Now let’s compile and install Dlib’s Python module.

# move to dlib's root directory cd dlib-19.6 python setup.py install # clean up(this step is required if you want to build dlib for both Python2 and Python3) rm -rf dist rm -rf tools/python/build rm python_examples/dlib.so

We have cleaned up few files and directories because Dlib creates Python modules for Python2 and Python3 with the same name. Suppose you ran the setup.py in Python2 virtual environment, it will generate dlib.so in python_examples directory. Now if you deactivate Python2 virtual env, activate Python3 virtual env and run setup.py file, it will replace dlib.so (which was compiled with Python2) in python_examples directory with newer one (which is compiled with Python3). When you will try to run any python_example from within this directory, it will import this dlib.so instead of one located in site-packages or dist-packages directory and throw an error. Although this error won’t occur is a local copy of dlib.so is not present in current directory but it is better to remove local copies to avoid any confusion.

Читайте также:  Html shopping website templates

For consistency, we have installed Python and C++ binaries of Dlib using the same source code.

If you are going to use only Python module of Dlib you can also install Python bindings for Dlib using pip.

Now you can exit from Python virtual environment.

Now, whenever you are going to run Python scripts which use Dlib you have to activate the virtual environment using workon command.

Subscribe & Download Code

If you liked this article and would like to download code (C++ and Python) and example images used in this post, please click here. Alternately, sign up to receive a free Computer Vision Resource Guide. In our newsletter, we share OpenCV tutorials and examples written in C++/Python, and Computer Vision and Machine Learning algorithms and news.

Источник

flavindias / install-dlib-ubuntu-with-cuda

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters

# In this post, we will provide step by step instructions on how to install Dlib on Ubuntu.
# Step 1: Install OS libraries
sudo apt-get install build-essential cmake pkg-config
sudo apt-get install libx11-dev libatlas-base-dev
sudo apt-get install libgtk-3-dev libboost-python-dev
Step 2: Install Python libraries
sudo apt-get install python-dev python-pip python3-dev python3-pip
sudo -H pip2 install -U pip numpy
sudo -H pip3 install -U pip numpy
# We will use Virtual Environment to install Python libraries. It is generally a good practice in order to separate your project environment and global environment.
# Install virtual environment
sudo pip2 install virtualenv virtualenvwrapper
sudo pip3 install virtualenv virtualenvwrapper
echo «# Virtual Environment Wrapper» >> ~/.bashrc
echo «source /usr/local/bin/virtualenvwrapper.sh» >> ~/.bashrc
source ~/.bashrc
############ For Python 2 ############
# create virtual environment
mkvirtualenv facecourse-py2 -p python2
workon facecourse-py2
# now install python libraries within this virtual environment
pip install numpy scipy matplotlib scikit-image scikit-learn ipython
# quit virtual environment
deactivate
######################################
############ For Python 3 ############
# create virtual environment
mkvirtualenv facecourse-py3 -p python3
workon facecourse-py3
# now install python libraries within this virtual environment
pip install numpy scipy matplotlib scikit-image scikit-learn ipython
# quit virtual environment
deactivate
######################################
#Step 3: Compile DLib
# Install GCC v6 to CUDA ENABLE
sudo apt-get update && \
sudo apt-get install build-essential software-properties-common -y && \
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y && \
sudo apt-get update && \
sudo apt-get install gcc-6 g++-6 -y && \
sudo update-alternatives —install /usr/bin/gcc gcc /usr/bin/gcc-6 60 —slave /usr/bin/g++ g++ /usr/bin/g++-6 && \
gcc -v
#Step 3.1: Compile C++ binary
#Davis King, creator of Dlib, recommends using CMake for using Dlib in your code.
#But if you want to use Dlib as a library follow these steps:
wget http://dlib.net/files/dlib-19.17.tar.bz2
tar xvf dlib-19.17.tar.bz2
cd dlib-19.17/
mkdir build
cd build
cmake ..
cmake —build . —config Release
sudo make install
sudo ldconfig
cd ..
#Now you can use pkg-config to provide path to Dlib’s include directory and link Dlib library file.
pkg-config —libs —cflags dlib-1
#Step 3.2: Compile Python module
#Activate Python virtual environment.
############ For Python 2 ############
workon facecourse-py2
############ For Python 3 ############
workon facecourse-py3
#Now let’s compile and install Dlib’s Python module.
# move to dlib’s root directory
cd dlib-19.6
python setup.py install
# clean up(this step is required if you want to build dlib for both Python2 and Python3)
rm -rf dist
rm -rf tools/python/build
rm python_examples/dlib.so
#We have cleaned up few files and directories because Dlib creates Python modules for Python2 and Python3 with the same name. Suppose you ran the setup.py in Python2 virtual environment, it will generate dlib.so in python_examples directory. Now if you deactivate Python2 virtual env, activate Python3 virtual env and run setup.py file, it will replace dlib.so (which was compiled with Python2) in python_examples directory with newer one (which is compiled with Python3). When you will try to run any python_example from within this directory, it will import this dlib.so instead of one located in site-packages or dist-packages directory and throw an error. Although this error won’t occur is a local copy of dlib.so is not present in current directory but it is better to remove local copies to avoid any confusion.
#For consistency, we have installed Python and C++ binaries of Dlib using the same source code.
#If you are going to use only Python module of Dlib you can also install Python bindings for Dlib using pip.
pip install dlib
#Now you can exit from Python virtual environment.
deactivate
# Now, whenever you are going to run Python scripts which use Dlib you have to activate the virtual environment using workon command.
Читайте также:  Http analytics tgl net ru login php

Источник

Оцените статью