Skip to main content

UniFace: A Comprehensive Library for Face Detection, Recognition, Tracking, Landmark Analysis, Face Parsing, Gaze Estimation, Age, and Gender Detection

Project description

UniFace: All-in-One Face Analysis Library

PyPI Version Python Version License Github Build Status PyPI Downloads UniFace Documentation Kaggle Badge Discord

UniFace - All-in-One Open-Source Face Analysis Library

UniFace is a lightweight, production-ready face analysis library built on ONNX Runtime. It provides high-performance face detection, recognition, landmark detection, face parsing, gaze estimation, and attribute analysis with hardware acceleration support across platforms.


Features

  • Face Detection — RetinaFace, SCRFD, YOLOv5-Face, and YOLOv8-Face with 5-point landmarks
  • Face Recognition — AdaFace, ArcFace, EdgeFace, MobileFace, and SphereFace embeddings
  • Face Tracking — Multi-object tracking with BYTETracker for persistent IDs across video frames
  • Facial Landmarks — 106-point landmark localization module (separate from 5-point detector landmarks)
  • Face Parsing — BiSeNet semantic segmentation (19 classes), XSeg face masking
  • Gaze Estimation — Real-time gaze direction with MobileGaze
  • Head Pose Estimation — 3D head orientation (pitch, yaw, roll) with 6D rotation representation
  • Attribute Analysis — Age, gender, race (FairFace), and emotion
  • Vector Store — FAISS-backed embedding store for fast multi-identity search
  • Anti-Spoofing — Face liveness detection with MiniFASNet
  • Face Anonymization — 5 blur methods for privacy protection
  • Hardware Acceleration — ARM64 (Apple Silicon), CUDA (NVIDIA), CPU

Visual Examples

Face Detection
Gaze Estimation
Head Pose Estimation
Age & Gender
Face Verification
106-Point Landmarks
Face Parsing
Face Segmentation
Face Anonymization

Installation

Standard installation

pip install uniface

GPU support (CUDA)

pip install uniface[gpu]

From source (latest version)

git clone https://github.com/yakhyo/uniface.git
cd uniface && pip install -e .

FAISS vector store

pip install faiss-cpu   # or faiss-gpu for CUDA

Optional dependencies

  • Emotion model uses TorchScript and requires torch: pip install torch (choose the correct build for your OS/CUDA)
  • YOLOv5-Face and YOLOv8-Face support faster NMS with torchvision: pip install torch torchvision then use nms_mode='torchvision'

Model Downloads and Cache

Models are downloaded automatically on first use and verified via SHA-256.

Default cache location: ~/.uniface/models

Override with the programmatic API or environment variable:

from uniface.model_store import get_cache_dir, set_cache_dir

set_cache_dir('/data/models')
print(get_cache_dir())  # /data/models
export UNIFACE_CACHE_DIR=/data/models

Quick Example (Detection)

import cv2
from uniface.detection import RetinaFace

detector = RetinaFace()

image = cv2.imread("photo.jpg")
if image is None:
    raise ValueError("Failed to load image. Check the path to 'photo.jpg'.")

faces = detector.detect(image)

for face in faces:
    print(f"Confidence: {face.confidence:.2f}")
    print(f"BBox: {face.bbox}")
    print(f"Landmarks: {face.landmarks.shape}")

Face Detection Model Output


Example (Face Analyzer)

import cv2
from uniface import FaceAnalyzer

# Zero-config: uses SCRFD (500M) + ArcFace (MobileNet) by default
analyzer = FaceAnalyzer()

image = cv2.imread("photo.jpg")
if image is None:
    raise ValueError("Failed to load image. Check the path to 'photo.jpg'.")

faces = analyzer.analyze(image)

for face in faces:
    print(face.bbox, face.embedding.shape if face.embedding is not None else None)

With attributes:

from uniface import FaceAnalyzer, AgeGender

analyzer = FaceAnalyzer(attributes=[AgeGender()])
faces = analyzer.analyze(image)

for face in faces:
    print(f"{face.sex}, {face.age}y, embedding={face.embedding.shape}")

Jupyter Notebooks

Example Colab Description
01_face_detection.ipynb Open In Colab Face detection and landmarks
02_face_alignment.ipynb Open In Colab Face alignment for recognition
03_face_verification.ipynb Open In Colab Compare faces for identity
04_face_search.ipynb Open In Colab Find a person in group photos
05_face_analyzer.ipynb Open In Colab All-in-one analysis
06_face_parsing.ipynb Open In Colab Semantic face segmentation
07_face_anonymization.ipynb Open In Colab Privacy-preserving blur
08_gaze_estimation.ipynb Open In Colab Gaze direction estimation
09_face_segmentation.ipynb Open In Colab Face segmentation with XSeg
10_face_vector_store.ipynb Open In Colab FAISS-backed face database
11_head_pose_estimation.ipynb Open In Colab Head pose estimation (pitch, yaw, roll)
12_face_recognition.ipynb Open In Colab Standalone face recognition pipeline

Documentation

Full documentation: https://yakhyo.github.io/uniface/

Resource Description
Quickstart Get up and running in 5 minutes
Model Zoo All models, benchmarks, and selection guide
API Reference Detailed module documentation
Tutorials Step-by-step workflow examples
Guides Architecture and design principles
Datasets Training data and evaluation benchmarks

Execution Providers (ONNX Runtime)

from uniface.detection import RetinaFace

# Force CPU-only inference
detector = RetinaFace(providers=["CPUExecutionProvider"])

See more in the docs: https://yakhyo.github.io/uniface/concepts/execution-providers/


Datasets

Task Training Dataset Models
Detection WIDER FACE RetinaFace, SCRFD, YOLOv5-Face, YOLOv8-Face
Recognition MS1MV2 MobileFace, SphereFace
Recognition WebFace600K ArcFace
Recognition WebFace4M / 12M AdaFace
Recognition MS1MV2 EdgeFace
Gaze Gaze360 MobileGaze
Head Pose 300W-LP HeadPose (ResNet, MobileNet)
Parsing CelebAMask-HQ BiSeNet
Attributes CelebA, FairFace, AffectNet AgeGender, FairFace, Emotion

See Datasets documentation for download links, benchmarks, and details.


Licensing and Model Usage

UniFace is MIT-licensed, but several pretrained models carry their own licenses. Review: https://yakhyo.github.io/uniface/license-attribution/

Notable examples:

  • YOLOv5-Face and YOLOv8-Face weights are GPL-3.0
  • FairFace weights are CC BY 4.0

If you plan commercial use, verify model license compatibility.


References

Feature Repository Training Description
Detection retinaface-pytorch RetinaFace PyTorch Training & Export
Detection yolov5-face-onnx-inference - YOLOv5-Face ONNX Inference
Detection yolov8-face-onnx-inference - YOLOv8-Face ONNX Inference
Tracking bytetrack-tracker - BYTETracker Multi-Object Tracking
Recognition face-recognition MobileFace, SphereFace Training
Recognition edgeface-onnx - EdgeFace ONNX Inference
Parsing face-parsing BiSeNet Face Parsing
Parsing face-segmentation - XSeg Face Segmentation
Gaze gaze-estimation MobileGaze Training
Head Pose head-pose-estimation Head Pose Training (6DRepNet-style)
Anti-Spoofing face-anti-spoofing - MiniFASNet Inference
Attributes fairface-onnx - FairFace ONNX Inference

*SCRFD and ArcFace models are from InsightFace.


Contributing

Contributions are welcome. Please see CONTRIBUTING.md.

Support

If you find this project useful, consider giving it a ⭐ on GitHub — it helps others discover it!

Questions or feedback:

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uniface-3.4.0.tar.gz (91.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uniface-3.4.0-py3-none-any.whl (114.6 kB view details)

Uploaded Python 3

File details

Details for the file uniface-3.4.0.tar.gz.

File metadata

  • Download URL: uniface-3.4.0.tar.gz
  • Upload date:
  • Size: 91.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for uniface-3.4.0.tar.gz
Algorithm Hash digest
SHA256 be76265709809d1ce3e71bd771368d6b605b6748008d52378bc159e9f413ec2d
MD5 9e6a0f75765ba4aa0f8d4bbda0333ed5
BLAKE2b-256 42c2b2bd2c5de1a171cf3bc924272948bf41f3859cb675df589801d96894aa63

See more details on using hashes here.

File details

Details for the file uniface-3.4.0-py3-none-any.whl.

File metadata

  • Download URL: uniface-3.4.0-py3-none-any.whl
  • Upload date:
  • Size: 114.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for uniface-3.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2be6fd89f5c7c79a1977cb41d553199edfea78eeddf5c1c6a2b9f4847be0fe55
MD5 00cd4e7750f1a045f514c16430ca0a45
BLAKE2b-256 d25206220640bf48243ff510cf11ad23ad4b9ea970dc28d657f65ab21d92ebbc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page