-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the face alignment performance in detect_faces() #1409
base: master
Are you sure you want to change the base?
Conversation
When I perform current design and your change of detection module for this image, I am getting these results: current design:
opencv deteceted 5 faces
ssd deteceted 3 faces
dlib deteceted 4 faces
mtcnn deteceted 6 faces
retinaface deteceted 7 faces
yunet deteceted 4 faces
yolov8 deteceted 8 faces
centerface deteceted 6 faces
your change:
opencv deteceted 5 faces
ssd deteceted 4 faces
dlib deteceted 4 faces
mtcnn deteceted 5 faces
retinaface deteceted 6 faces
yunet deteceted 4 faces
yolov8 deteceted 7 faces
centerface deteceted 7 faces You can also find the detection results here: As you can see, your change causes not to find faces close to image boundaries for most of detectors. I am sharing my test code here: from deepface import DeepFace
img_path = "dataset/selfie-many-people.jpg"
detector_backends = [
"opencv",
"ssd",
"dlib",
"mtcnn",
"retinaface",
"yunet",
"yolov8",
"centerface",
]
for detector_backend in detector_backends:
face_objs = DeepFace.extract_faces(
img_path=img_path,
detector_backend=detector_backend,
# expand_percentage=0,
)
print(f"{detector_backend} deteceted {len(face_objs)} faces")
fig = plt.figure(figsize=(10, 10))
for face_obj in face_objs:
face = face_obj["face"]
plt.imshow(face)
plt.axis("off")
plt.show() TLDR: current design can detect faces close to boundaries but your change cannot. |
Thanks for the feedback! I'm busy with Christmas right now, but I’ll check it carefully soon. For now, here are my thoughts:
P/S: Merry Christmas! Hope you enjoy the holiday season. 🎄 |
Of course, take your time. I hope you understand my concern. When increasing its time consumption performance, I don't want to decrease its detection performance. Enhancement should offer same accuracy performance or more. Here are my comments:
|
5a0eea1
to
421ef9e
Compare
Actually, the detection results in my design are the same as the current design when the Moreover, the above solution doesn’t fully preserve the detection improvements observed with models like ssd, centerface, and yunet(*). I propose adding these models in a skip-border-addition list, and the code would look like this: Additionally, for further clarification, in my design, yolov8 can detect all 7 faces, but faces near the border return outer-eye coordinates as (0,0), which affects alignment. The current design didn't have this problem because of the border, so please let me know if you want to add yolov8 to the skip-list in the list too. What do you think of these ideas? (*) For yunet, with a threshold of 0.8, the current design detects 4 faces, while my design detects 6. Perhaps we could consider lowering the threshold for better results. |
So, we are still adding borders to image. Why should we merge this PR then? I cannot see any reasonable improvements. |
The main improvement in my design lies in how the alignment input is adjusted, regardless of whether borders are added or not. Currently, the entire image is used as the input for alignment, and this process is repeated In my design, only the facial area is used as the input for each alignment operation. Since the entire image is significantly larger than the facial area, this optimization saves a considerable amount of processing time—especially when multiple faces are present in the image. I hope this explanation clarifies the benefits of the proposed changes. |
Tickets
#1244
#1406
What has been done
With this PR, the detect_faces() logic has been modified when alignment is enabled:
Sorry I didn't add a unit test case for #1244 as I promised. I think this bug can only be detected visually, since it’s hard to test automatically. But if an automated test is needed, I’d suggest using template matching algorithms.
How to test