deepface: Lightweight Face Recognition and Facial Attribute Analysis Library

deepface: Lightweight Face Recognition and Facial Attribute Analysis Library

Summary

deepface is a powerful yet lightweight Python library for face recognition and facial attribute analysis. It offers capabilities for age, gender, emotion, and race prediction, wrapping state-of-the-art models for robust performance. Developers can easily integrate advanced facial analysis into their applications with just a few lines of code.

Repository Info

Updated on November 20, 2025
View on GitHub

Introduction

deepface is a robust and lightweight Python library designed for advanced face recognition and comprehensive facial attribute analysis. It empowers developers to easily implement functionalities like age, gender, emotion, and race prediction. This hybrid framework integrates and wraps several state-of-the-art deep learning models, including VGG-Face, FaceNet, OpenFace, ArcFace, and DeepFace, ensuring high accuracy and flexibility. It simplifies the complex pipeline of face detection, alignment, normalization, representation, and verification, allowing users to perform sophisticated facial analysis with minimal code.

Installation

Getting started with deepface is straightforward. The easiest way to install the library and its prerequisites is via pip:

$ pip install deepface

Alternatively, you can install it from the source code to access the latest features:

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

Once installed, you can import and use deepface functionalities:

from deepface import DeepFace

Examples

deepface provides a simple API for various facial analysis tasks:

Face Verification

Determine if two facial images belong to the same person. The verify function returns a dictionary, with verified indicating the result and a confidence score.

result = DeepFace.verify(img1_path = "img1.jpg", img2_path = "img2.jpg")

Face Recognition

Identify a person from a database of faces. The find function searches for the identity of an input image within a specified database path, returning a list of pandas DataFrames.

dfs = DeepFace.find(img_path = "img1.jpg", db_path = "C:/my_db")

Facial Attribute Analysis

Analyze facial attributes such as age, gender, emotion, and race. The analyze function provides detailed predictions for each detected face.

objs = DeepFace.analyze(
  img_path = "img4.jpg", actions = ['age', 'gender', 'race', 'emotion']
)

Real-Time Analysis

Perform real-time face recognition and attribute analysis using a webcam. The stream function accesses your webcam and processes frames sequentially.

DeepFace.stream(db_path = "C:/database")

Embeddings

Extract multi-dimensional vector embeddings from facial images. These embeddings are crucial for similarity comparisons and can be obtained using the represent function.

embedding_objs = DeepFace.represent(img_path = "img.jpg")

Why Use deepface

deepface stands out for its comprehensive feature set and ease of use. It wraps numerous state-of-the-art face recognition models and detection backends, offering unparalleled flexibility and performance. Whether you need to verify identities, recognize faces in a database, or analyze facial attributes in real-time, deepface provides a robust and efficient solution. Its modular design allows for customization of models, detectors, and distance metrics, making it adaptable to various application requirements, from small-scale projects to large-scale facial recognition systems with vector databases and homomorphic encryption.

Links