CNN based face detection using dlib

srujan jack
MLCrunch
Published in
1 min readJul 17, 2020

If this is your first face identification story, I would recommend taking a look at this free course to learn the basics of face identification and deep learning.

CNN (Convolutional Neural Network) is a class of deep networking, it works really well for non-frontal faces at odd angles where HOG based detector is not good at it.

Dlib has CNN based face detection, trained with millions of images, and stored the trained model in a “.dat” file. Face detection weighted model file can be loaded as follows

dlib.cnn_face_detection_model_v1(“./face_detector.dat”)

Once the weighted model file is loaded, the model can be used to detect faces directly. The full source code is shown below.

Explanation: Step1 loads face detection model and step4 detect faces and return a list of faces from the image. Line# 15 goes through each face and draws a rectangle around it.

Advantages:

  • CNN based face detection is so accurate, it can find odd faces
  • It works on CPU but must faster on GPU
  • Very easy to use

Dis-Advantages:

  • Works slow on CPU
  • Doesn’t detect small faces (you can notice that CNN missed small faces from the output)

--

--