Face Recognition Using dlib’s State Of Art ‘face_recognition’
- General
Face Recognition Using dlib’s State Of Art ‘face_recognition’
Face Recognition
Recognize and manipulate faces from Python or from the command line with the world’s simplest face recognition library. Built using dlib’s state-of-the-art face recognition built with deep learning. The model has an accuracy of 99.38% on the Labeled Faces in the Wild benchmark.
This also provides a simple face_recognition command-line tool that lets you do face recognition on a folder of images from the command line!
Installing Dlib
1. Install os libraries
1 2 |
sudo apt-get install build-essential cmake pkg-config |
1 2 |
sudo apt-get install libx11-dev libatlas-base-dev |
1 2 |
sudo apt-get install libgtk-3-dev libboost-python-dev |
2.install python libraries
1 2 |
sudo apt-get install python-dev python-pip python3-dev python3-pip |
1 |
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
1 |
sudo pip3 install virtualenv virtualenvwrapper |
1 2 |
#create a virtual environment mkvirtualenv facecourse-py3 -p python3 |
1 |
workon facecourse-py3 |
1 2 |
# now install python libraries within this virtual environment pip install numpy scipy matplotlib scikit-image scikit-learn ipython |
Dlib installation without GPU support
1 2 |
$ workon # optional $ pip install dlib |
or you can compile the following code
1 2 3 4 5 6 7 8 9 10 |
$ workon <your env name here> # optional $ git clone https://github.com/davisking/dlib.git $ cd dlib $ mkdir build $ cd build $ cmake .. -DUSE_AVX_INSTRUCTIONS=1 $ cmake --build . $ cd .. $ python setup.py install --yes USE_AVX_INSTRUCTIONS |
Installing dlib with GPU support (optional)
If you do have a CUDA compatible GPU you can install dlib with GPU support, making facial recognition faster and more efficient.
For this, I recommend installing
1 2 3 4 5 6 7 8 9 |
$ workon <your env name here> # optional $ git clone https://github.com/davisking/dlib.git $ cd dlib $ mkdir build $ cd build $ cmake .. -DDLIB_USE_CUDA=1 -DUSE_AVX_INSTRUCTIONS=1 $ cmake --build . $ cd .. $ python setup.py install --yes USE_AVX_INSTRUCTIONS --yes DLIB_USE_CUDA |
Install the face_recognition package
1 2 |
$ workon <your env name here> # optional $ pip install face_recognition |
Install imutils( You’ll also need my package of convenience functions, imutils. You may install it in your Python virtual environment via pip)
1 2 |
$ workon <your env name here> # optional $ pip install imutils |
Now we can see the project setup, hit command tree
in the directory containing the project
In the dataset we create folders for every person and to create encodings we put images of those people to prepare encodings for.
We prepare encodings by running encode_faces.py
And encodings are saved in encodings.pickle file
Results demo:-
Related content
Auriga: Leveling Up for Enterprise Growth!
Auriga’s journey began in 2010 crafting products for India’s