Face Detection Models and their Performance Comparison
Here we discuss a few available and most used face detection deep learning-based models and their performance concerning the accuracy and computational cost.
Dlib :
Dlib is a modern C++ toolkit containing machine learning algorithms and tools for creating complex software in C++ to solve real-world problems. It conveniently has the necessary bindings that will enable you to run many tasks directly in Python. One of them we are going to try is Face Detection. To install Dlib follow the link.
Dlib offers different algorithms for face detection. One of them is a frontal face detector which works well. The detector is based on the histogram of oriented gradients (HOG) and linear SVM. It works well in the CPU itself.
import dlib
face_detector = dlib.get_frontal_face_detector() # face_detector
face_detector(img)==> rectangles[[(174, 134) (353, 313)]] # return an dlib.rectangles
Dlib front face detector is a light-weight package and executes with low computation power. It can even use to detect multiple faces in a single image. Sample prediction like...
MTCNN :
Stands for Multi-task Cascaded Convolutional Networks. It is a python package that can be installed easily and they provide a high-level API for face detection. Its performance is better than Dlib but it needs more computation than Dlib. It works in both GPU and CPU. It uses Tensorflow as a backend. It also supports multiple face detection in an image. The prediction of the same image in MTCNN results like...
When we compare these two results we can find that some of the occluded faces are not detected by Dlib but MTCNN detected it. Below is a simple snippet of MTCNN in python.
from mtcnn import MTCNN
face_detector = MTCNN()
face_detector.detect_faces(img)Returns:
[{'box': [208, 122, 155, 207],
'confidence': 1.0,
'keypoints': {'left_eye': (243, 205),
'mouth_left': (249, 276),
'mouth_right': (311, 274),
'nose': (271, 244),
'right_eye': (306, 203)}}]
MTCNN will also return facial keypoints like eyes, nose, mouth. To know more about MTCNN refer here.
Face Recognition
A simple library is available in python for face detection and recognition. It can also be used in the command line if needed. It is easy to install, by just running the command “pip install face_recognition”. It also supports multiple face detection in an image. The full documentation of the package is attached here. The small snippet of it
import face_recognition
face_recognition.face_locations(img)Output:
[(139, 366, 325, 180)] # return the face Location
Since it is built with a dlib in the back-end its performance is also similar to dlib. The sample detection is …
Here we can see that some of the occluded faces are not detected by it and the same thing happen in dlib prediction.
Tiny Face Detector in TensorFlow
Tensorflow based model trained with a large dataset. It is a pre-trained model where we can use this model for inference. The setup and git are referred to here. The advantage of this model is, it detects more accurately and precisely than all the existing models in real-time. But its computation time is much higher than other models. The reason is, it will scale the image in many ratios and try to predict faces and then combine the result with non-maximum suppression. The result of this model is …
The above sample will not highlight this model performance. It looks at the sample as MTCNN or another model. But if we use an image that holds many faces we can see the difference (link).
Here I have discussed more which can run in both CPU and GPU. The overall performance of the model is plotted below
From the plot, we can infer that Tiny Face Tensorflow take much computational cost whereas dlib and FaceRecoginition module consume low computation cost.
But in terms of accuracy Tiny face model is best compared to dlib.
So based on the application we need to select a model. In the case of real-time face detection, we can use dlib and MTCNN (if GPU is available) models where it results in a good performance.
In the case of face analysis or the case of a low-quality image we can use the Tiny Face Tensorflow model since it takes more computational time but we can achieve high accuracy.
Here I have attached my Git link for this blog.
I would be very happy to receive your queries and comments. Kindly post in the comments section. Do follow me for more ML/DL blogs.