tomas-gajarsky/facetorch

Python library for analysing faces using PyTorch

What it solves

Facetorch provides a unified, high-performance Python toolkit for facial detection and analysis. It solves the problem of having to manually integrate multiple disparate open-source face analysis models for different tasks—such as emotion recognition, deepfake detection, and face verification—by curating and optimizing them into a single, extensible library.

How it works

The library uses a central FaceAnalyzer class to orchestrate a pipeline of components:

  1. Reader: Loads the image into a tensor.
  2. Detector: Uses neural networks (like RetinaFace) to locate faces in the image.
  3. Unifier: Normalizes face sizes and scales them for consistent processing.
  4. Predictors: A collection of specialized neural networks that analyze specific features (e.g., facial expressions, action units, valence/arousal, and deepfake detection).
  5. Utilizers: Tools that handle the output, such as drawing bounding boxes or saving results.

To ensure high performance, the library optimizes models using TorchScript for accelerated execution on both CPU and GPU. It integrates with Hydra for configuration and Hugging Face Hub for automatic model downloading.

Who it’s for

Facetorch is designed for developers and researchers who need a flexible, scalable solution for facial analysis tasks and want to leverage community-driven open-source models without building the infrastructure from scratch.

Highlights

  • Comprehensive Analysis: Supports a wide range of tasks including facial expression recognition (FER), deepfake detection, face verification, and 3D facial alignment.
  • Performance Optimized: Uses TorchScript to speed up inference on CPU and GPU.
  • Extensible Architecture: Allows users to add new models by uploading a TorchScript file to Hugging Face Hub and adding a YAML configuration.
  • Reproducible Setup: Provides Docker and conda-lock support for consistent environment management.