UniFace: 15 Face Analysis Tasks in One Python Library

By Prahlad Menon 2 min read

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

TaskModels
Face DetectionRetinaFace, SCRFD, CenterFace, YOLOv5-Face, YOLOv8-Face, BlazeFace
Face RecognitionAdaFace, ArcFace, EdgeFace, MobileFace, SphereFace
Face TrackingBYTETracker (persistent IDs across video frames)
Facial Landmarks2d106det (106), PIPNet (98/68), Face Mesh (468/478, 3D)
Face ParsingBiSeNet (19 classes), XSeg masking
Portrait MattingMODNet (trimap-free)
Gaze EstimationMobileGaze (ResNet-18/34/50, MobileNetV2)
Head Pose6D rotation (pitch/yaw/roll)
DemographicsAgeGender, FairFace (age group, sex, race)
EmotionAffectNet-7 and AffectNet-8
Face StatesFaceAttribNet: eyes, glasses, sunglasses, mask
Face QualityeDifFIQA (T/S/M/L)
Anti-SpoofingMiniFASNet liveness
Anonymization5 blur methods
Vector StoreFAISS-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 populated
  • age, 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?

FeatureUniFaceDeepFaceInsightFace
Unified APIβœ…PartialPartial
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: