How to use DeepFace.detectFace() to actually detect a several faces in an image?

Question:

I am using deep face library in order to get several faces in one picture, DeepFace.detectFace(), only detect one face, but if I use the backends separately without use DeepFace I can extract all faces, is it possible to use DeepFace.detectFace() in order to get all faces in one photo?

Thanks

Asked By: Tlaloc-ES

||

Answers:

DeepFace expects you to feed an image with a single face. You are still able to do extract faces with deepface.

from deepface.detectors import FaceDetector
import cv2

img_path = "couple.jpg"
detector_name = "opencv"

img = cv2.imread(img_path)

detector = FaceDetector.build_model(detector_name) #set opencv, ssd, dlib, mtcnn or retinaface

obj = FaceDetector.detect_faces(detector, detector_name, img)

print("there are ",len(obj)," faces")
Answered By: johncasey

I just found this question so adding my 2 cents here.

The deepFace has 2 face detection methods: detect_face(), detect_faces(). I tried both of them on the input image which had 2 faces. The detect_face() method returned 2 faces while the detect_faces() returned only 1.

I also explored the retinaFace library. The RetinaFace.detect_faces(input_img) works better than the above 2. It will return a dictionary containing more details like the position of the detected faces, conf-score, facial area, landmarks, etc.

detector = FaceDetector.build_model('opencv')
faces_1 = FaceDetector.detect_face(detector, 'opencv', img1)
faces_2 = FaceDetector.detect_faces(detector, 'opencv', img1)
faces_3 = RetinaFace.detect_faces(img1)

print(len(faces_1))
print(len(faces_2))
print(len(faces_3))
print(faces_3)

Output:

2
1
2
{'face_1': {'score': 0.9995673298835754, 'facial_area': [373, 91, 461, 205], 'landmarks': {'right_eye': [391.61844, 136.72823], 'left_eye': [433.21796, 140.49823], 'nose': [407.73734, 166.59834], 'mouth_right': [390.31372, 171.94685], 'mouth_left': [433.46893, 175.20789]}}, 
'face_2': {'score': 0.999311089515686, 'facial_area': [183, 67, 275, 188], 'landmarks': {'right_eye': [207.43852, 110.758644], 'left_eye': [249.73247, 118.7763], 'nose': [223.10075, 146.06569], 'mouth_right': [200.28362, 148.65518], 'mouth_left': [244.21638, 155.8222]}}}

Comparison between deepface and retinaFace detect face methods

Answered By: Tariq.

You can use this library which is a simple wrapper for deepface.

https://github.com/Moahmmed1900/face_embedding

And then just follow the installation and usage steps.

Answered By: Mohammed Nadershah