UniFace: 15 Face Analysis Tasks in One Python Library
Face analysis in Python usually means stitching together five different libraries with incompatible interfaces. UniFace consolidates 15 face tasks into one lightweight package with a consistent API.
pip install "uniface[cpu]" # or uniface[gpu] for CUDA
Repo: github.com/yakhyo/uniface
Docs: yakhyo.github.io/uniface
Demo: Hugging Face Space
One API, Fifteen Tasks
| Task | Models |
|---|---|
| Face Detection | RetinaFace, SCRFD, CenterFace, YOLOv5-Face, YOLOv8-Face, BlazeFace |
| Face Recognition | AdaFace, ArcFace, EdgeFace, MobileFace, SphereFace |
| Face Tracking | BYTETracker (persistent IDs across video frames) |
| Facial Landmarks | 2d106det (106), PIPNet (98/68), Face Mesh (468/478, 3D) |
| Face Parsing | BiSeNet (19 classes), XSeg masking |
| Portrait Matting | MODNet (trimap-free) |
| Gaze Estimation | MobileGaze (ResNet-18/34/50, MobileNetV2) |
| Head Pose | 6D rotation (pitch/yaw/roll) |
| Demographics | AgeGender, FairFace (age group, sex, race) |
| Emotion | AffectNet-7 and AffectNet-8 |
| Face States | FaceAttribNet: eyes, glasses, sunglasses, mask |
| Face Quality | eDifFIQA (T/S/M/L) |
| Anti-Spoofing | MiniFASNet liveness |
| Anonymization | 5 blur methods |
| Vector Store | FAISS-backed embedding search |
Quick Start
import cv2
from uniface import FaceAnalyzer, FairFace
analyzer = FaceAnalyzer(predictors=[FairFace()])
for face in analyzer.analyze(cv2.imread("photo.jpg")):
print(face.bbox, face.sex, face.age_group, face.embedding.shape)
Thatβs it. Detection, alignment, recognition, and demographics in four lines.
How It Works
FaceAnalyzer runs detection, alignment, and recognition by default. Additional models are opt-in β you pass predictors for the tasks you need:
from uniface import FaceAnalyzer, FairFace, AffectNet, MiniFASNet
# Add emotion and anti-spoofing
analyzer = FaceAnalyzer(predictors=[
FairFace(), # age, sex, race
AffectNet(), # emotion
MiniFASNet() # liveness/spoofing
])
Every face object has:
bbox,confidence,landmarks,embeddingβ always populatedage,sex,race,emotion,quality,face_statesβ None until you add the predictor
This lazy-loading design means you donβt pay compute costs for features you donβt use.
Installation
# CPU or Apple Silicon
pip install "uniface[cpu]"
# NVIDIA CUDA
pip install "uniface[gpu]"
# Latest pre-release
pip install --pre "uniface[cpu]"
Weights download automatically on first use, verified by SHA-256 checksums.
Example Tasks
Face Detection
from uniface import FaceDetector
detector = FaceDetector() # defaults to SCRFD
faces = detector.detect(image)
for face in faces:
print(face.bbox, face.confidence)
Face Recognition
from uniface import FaceRecognizer
recognizer = FaceRecognizer() # defaults to AdaFace
embedding = recognizer.get_embedding(aligned_face)
# Compare embeddings
similarity = recognizer.compare(embedding1, embedding2)
Facial Landmarks (106 points)
from uniface import LandmarkDetector
landmarker = LandmarkDetector(model="2d106det")
landmarks = landmarker.detect(face_image) # 106 (x, y) points
Face Mesh (468/478 points, 3D)
from uniface import FaceMesh
mesh = FaceMesh()
points_3d = mesh.detect(face_image) # 468 or 478 3D points
Gaze Estimation
from uniface import GazeEstimator
gaze = GazeEstimator()
pitch, yaw = gaze.estimate(face_image)
Anti-Spoofing
from uniface import MiniFASNet
spoof_detector = MiniFASNet()
is_real, score = spoof_detector.predict(face_image)
Face Parsing (19 semantic classes)
from uniface import BiSeNet
parser = BiSeNet()
segmentation_mask = parser.parse(face_image)
# Classes: skin, nose, eyes, eyebrows, ears, mouth, lips, hair, etc.
Portrait Matting
from uniface import MODNet
matting = MODNet()
alpha_mask = matting.predict(image) # trimap-free
Video Tracking
from uniface import FaceTracker
tracker = FaceTracker()
for frame in video_frames:
tracked_faces = tracker.track(frame)
for face in tracked_faces:
print(f"ID: {face.track_id}, bbox: {face.bbox}")
Anonymization
from uniface import FaceAnonymizer
anonymizer = FaceAnonymizer(method="gaussian") # or pixelate, blur, etc.
anonymized_image = anonymizer.anonymize(image)
FAISS Vector Store
Built-in embedding search for face recognition at scale:
from uniface import FaceStore
store = FaceStore()
store.add("person_1", embedding1)
store.add("person_2", embedding2)
# Find matches
matches = store.search(query_embedding, k=5)
Why Use This Over DeepFace/InsightFace?
| Feature | UniFace | DeepFace | InsightFace |
|---|---|---|---|
| Unified API | β | Partial | Partial |
| Gaze Estimation | β | β | β |
| Face Parsing | β | β | β |
| Portrait Matting | β | β | β |
| Anti-Spoofing | β | β | β |
| Face Quality | β | β | β |
| Video Tracking | β | β | β |
| Lightweight | β | β | β |
| Apple Silicon | β | β | Partial |
UniFace fills gaps that other libraries donβt cover β particularly gaze, anti-spoofing, quality assessment, and matting.
Use Cases
Identity Verification:
- Detection + Recognition + Anti-Spoofing + Quality
Video Analytics:
- Detection + Tracking + Demographics + Emotion
Content Moderation:
- Detection + Face States (glasses, mask) + Anonymization
AR/VR:
- Face Mesh + Gaze + Head Pose
Access Control:
- Detection + Recognition + Liveness + FAISS Store
Platform Support
- CPU: Full support
- Apple Silicon: Optimized via ONNX Runtime
- CUDA: Full GPU acceleration
Links:
- Repo: github.com/yakhyo/uniface
- Docs: yakhyo.github.io/uniface
- PyPI: pypi.org/project/uniface
- Demo: huggingface.co/spaces/yakhyo/uniface
- Notebooks: yakhyo.github.io/uniface/notebooks