Overseas access: www.kdjingpai.com
Bookmark Us
Current Position:fig. beginning " AI Answers

How to use DeepFace for facial attribute analysis?

2025-09-10 2.3 K

Facial attribute analysis using DeepFace is very simple and can be implemented with just a few lines of code. Below are detailed step-by-step instructions:

1. Install the DeepFace library:

It can be installed directly via PyPI:

pip install deepface

Or install from source:

git clone https://github.com/serengil/deepface.git
cd deepface
pip install -e .

2. Import the library and use the analyze function:

After importing DeepFace, facial attributes can be analyzed using the analyze function. The function can specify the specific attributes to be analyzed, including age, gender, emotion and race.

from deepface import DeepFace

result = DeepFace.analyze(img_path="img.jpg",
actions=['age', 'gender', 'emotion', 'race'])
print(result)

3. View the results of the analysis:

The analyze function returns a dictionary containing the results of analyzing various attributes. Example:

  • Age will be the estimated number
  • Gender would be the probability value of male/female
  • Emotions give scores for anger, fear, happiness, and many other emotions
  • Race will give probability distributions for different races

Advanced Usage:

It is also possible to analyze multiple images at the same time, using the batch prediction feature:

results = DeepFace.analyze(img_paths=["img1.jpg", "img2.jpg"], 
actions=['age', 'gender', 'emotion', 'race'])
print(results)

Recommended

Can't find AI tools? Try here!

Just type in the keyword Accessibility Bing SearchYou can quickly find all the AI tools on this site.

Top