Face recognition with OpenCV, Python, and deep learning

Face Recognition in video streaming using: 
  • OpenCv
  • Python 2.7
  • Deep Learning

The deep learning-based facial embedding we’ll be using

  • Highly accurate
  • Capable of being executed in  real time

The deep learning algorithm is used deep metric learning. The real-valued feature vector wants to be outputted.

For the dlib facial recognition network, the output feature is  128-d  (ie, a list of 128 real-valued numbers) that is used to  quantify the face . Training the network is done using  triplets :

Figure 1:  Facial recognition via deep metric learning involves a „triplet training step.“ The triplet of 3 unique faces images – 2 of the 3 are the same person. The NN generates a 128-d vector for each of the 3 face images. For the 2 face images of the same person, we tweak the neural network weights to make the vector closer via distance metric. Image credit:  Adam Geitgey’s  „Machine Learning is Fun“  blog

Three images are inputted to the network:

  • Two of these images are faces of the  same  person.
  • The third image is a  random  face from our dataset and is  not  the same person as the other two images.

As an example, let’s again consider  Figure 1  above where three images are provided: one of Chad Smith and two of Will Ferrell.

The network quantifies the faces, constructing the 128-D embedding (quantification) for each.

From there, the general idea is to  tweak the weights  of the neural network so that the 128- inch measurements of the two Will Ferrel wants to be  closer to each other  and farther from the measurements for Chad Smith.

The network architecture for face recognition is based on the  Residual Learning for Image Recognition  paper by He et al.

The network itself was created by  Davis King  on a dataset of ~ 3 million images. On the  Labeled Faces in the Wild (LFW)  the network compares to other state-of-the-art methods, reaching  99.38% accuracy .

Both Davis King (creator of  dlib ) and  Adam Geitgey  (the author of the  face_recognition module  we’ll be using shortly).

The above articles provide more details on how to do deep learning facial skills.

Install face recognition libraries

In order to perform the recognition with Python and OpenCV the following two additional libraries needs to be installed:

The dlib library, maintained by  Davis King , contains the implementation of „deep metric learning“ which is the actual recognition process.

The  face_recognition   library, created by  Adam Geitgey , wraps  around  dlib’s facial recognition functionality, making it easier to work with.

It’s assumed that the  OpenCV is installed on your system . If not, no worries – just visit the  OpenCV install tutorials  page.

From there, install  dlib   and the  face_recognition   packages.

Installing  dlib without  GPU support

If you do not have a GPU you can install  dlib   using pip by  following this guide :

Or you can compile from source:

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  dlib   from source as you’ll have more control over the build:

Install the  face_recognition package

The  face_recognition module  is installable via a simple pip command:

Install imutils

You’ll need my package of convenience functions,  imutils . You can install it in your Python virtual environment via pip:

Schreibe einen Kommentar