serengil / deepface

A Lightweight Face Recognition and Facial Attribute Analysis (Age, Gender, Emotion and Race) Library for Python
https://www.youtube.com/watch?v=WnUVYQP4h44&list=PLsS_1RYmYQQFdWqxQggXHynP1rqaYXv_E&index=1
MIT License
14.34k stars 2.2k forks source link

[Question] Is there way to detect all faces and then use analyze() on each? #419

Closed santoshbs closed 2 years ago

santoshbs commented 2 years ago

When I feed an image with multiple people in it to the DeepFace.analyze(), the function seems to return age, gender, etc. information for only one of the faces. Is there a way to first extract all faces and then analyze() age, gender, etc. for each face?

serengil commented 2 years ago

Yes, you can!

from retinaface import RetinaFace
from deepface import DeepFace

faces = RetinaFace.extract_faces("img.jpg")
for face in faces:
    obj = DeepFace.analyze(img)
    print(obj["age"])