Deepface Face recognition

Saaisri
featurepreneur
Published in
4 min readJul 23, 2022

DeepFace is one of the most popular open source for Facial Recognition Library.

Facial recognition has been a hot topic for several decades. And while there are different facial recognition libraries available, DeepFace has become widely popular and is used in numerous face recognition applications.

What is Deepface?

DeepFace is the most lightweight face recognition and facial attribute analysis library for Python. The open-sourced DeepFace library includes all leading-edge AI models for face recognition and automatically handles all procedures for facial recognition in the background.

While you can run DeepFace with just a few lines of code, you don’t need to acquire in-depth knowledge about all the processes behind it. In fact, you simply import the library and pass the exact image path as an input.

If you run face recognition with DeepFace, you get access to a set of features:

  • Face Verification: The task of face verification refers to comparing a face with another to verify if it is a match or not. Hence, face verification is commonly used to compare a candidate’s face to another. This can be used to confirm that a physical face matches the one in an ID document.
  • Face Recognition: The task refers to finding a face in an image database. Performing face recognition requires running face verification many times.
  • Facial Attribute Analysis: The task of facial attribute analysis refers to describing the visual properties of face images. Accordingly, facial attributes analysis is used to extract attributes such as age, gender classification, emotion analysis, or race/ethnicity prediction.
  • Real-Time Face Analysis: This feature includes testing face recognition and facial attribute analysis with the real-time video feed of your webcam.

In modern face recognition there are 4 steps:

  • Detect
  • Align
  • Represent
  • Classify

How do we use Deepface ?

Deepface is an open-source project written in Python and licensed under the MIT License. Developers are permitted to use, modify and distribute the library in both a private or commercial context.

pip install deepface

Import the library

from deepface import DeepFace

Facial Verification

This function verifies face pairs as same person or different persons. It expects exact image paths as inputs. Passing numpy or based64 encoded images is also welcome. Then, it is going to return a dictionary and you should check just its verified key.

result = DeepFace.verify(img1_path = "img1.jpg", img2_path = "img2.jpg")

Face recognition

Face recognition requires applying face verification many times. Herein, deepface has an out-of-the-box find function to handle this action. It’s going to look for the identity of input image in the database path and it will return pandas data frame as output.

df = DeepFace.find(img_path = "img1.jpg", db_path = "C:/workspace/my_db")

How does face recognition works?

Three acts on detected face rectangles are carried out by DeepFace’s paper

Face Pattern Recognition

Six unique areas of the face (both eyes, the tip of the nose, the corners of both mouths, and the middle of the lower lip) are detected by two-dimensional orientation and the image’s location and size are changed to match.

Using Support Vector Regression, which is a function called Local Binary Pattern, feature point identification is used.

This feature point is further increased to 67 points in the three-dimensional alignment, and the three-dimensional location of the feature point is calculated by corresponding to the corresponding reference point prepared in advance of the normal face 3D model (the one averaging the face 3D model data set).

Matrix formation

We approximate the camera matrix on the basis of this which projects the points of three-dimensional space on the camera plane.

The direction of the feature point is determined when taken from the front.

At the same time, polygons with feature points as vertices are created and the pixel values of the original image are refined on the corresponding front image triangle.

The representation of the front face can be derived from the image faced diagonally in this direction.

Deep Neural Network specs

Using convolution/pulling layers to capture positional characteristics is typical in image and face recognition.

On the other hand, DeepFace is an alignment of the input image, so there is not much need for the position.

For positional features, low-order characteristics (edges, textures, gradients, etc) are appropriate, but higher-order characteristics (eyes, nose, lips, and larger face parts) are more likely to catch different features for different positions.

After the third sheet, DeepFace uses various weights for each position. Furthermore, except for the first layer, pooling processing is not undertaken.

--

--