tomas-gajarsky/facetorch

Python library for analysing faces using PyTorch

What it solves

Facetorch provides a unified, scalable toolkit for facial detection and analysis. It solves the problem of fragmented open-source face analysis models by curating community models, packaging them into portable formats, and providing a standardized pipeline for reading, detecting, and analyzing facial features.

How it works

The library uses a central orchestrator called FaceAnalyzer that manages a sequential pipeline:

  1. Reader: Loads images from various sources (local paths, tensors, NumPy arrays, PIL images, or bytes).
  2. Detector: Uses a neural network (e.g., RetinaFace) to locate faces in the image.
  3. Unifier: Normalizes and resizes detected faces to a consistent format.
  4. Predictors: A suite of specialized neural networks that analyze specific facial attributes, such as facial expression recognition (FER), face verification, and embedding generation.
  5. Utilizers: Components that handle the output, such as drawing bounding boxes or saving results.

Models are serialized using torch.export (.pt2 format), allowing them to run without the original source code at inference time and supporting torch.compile for performance optimization.

Who it’s for

It is designed for developers and researchers who need a flexible, high-performance facial analysis system that is easy to deploy via Python or Docker and supports both CPU and GPU environments.

Highlights

  • Portable Models: Uses .pt2 serialization so no model source code is required during inference.
  • Flexible Input: Supports a wide range of input types including tensors, NumPy arrays, and PIL images through a single pipeline.
  • Curation & Governance: Curates community models with a strict manifest for validation, provenance, and rights approval.
  • Customizable Configuration: Integrated with Hydra and OmegaConf for easy setup overrides.
  • Deployment Ready: Provides official Docker images and supports fast package management via uv and conda-lock.

Related

  • Project
  • Project
  • Project
  • Project
  • Project