SkillAgentSearch skills...

Facetorch

Python library for analysing faces using PyTorch

Install / Use

/learn @tomas-gajarsky/Facetorch

README

facetorch

build lint PyPI Conda (channel only) PyPI - License <a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>

<a href="https://huggingface.co/spaces/tomas-gajarsky/facetorch-app"> <img src="https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue" alt="Hugging Face Spaces"> </a> <a target="_blank" href="https://colab.research.google.com/github/tomas-gajarsky/facetorch/blob/main/notebooks/facetorch_notebook_demo.ipynb"> <img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/> </a>

User Guide, Documentation, ChatGPT facetorch guide

Docker Hub (GPU)

Facetorch is a Python library designed for facial detection and analysis, leveraging the power of deep neural networks. Its primary aim is to curate open-source face analysis models from the community, optimize them for high performance using TorchScript, and integrate them into a versatile face analysis toolkit. The library offers the following key features:

  1. Customizable Configuration: Easily configure your setup using Hydra and its powerful OmegaConf capabilities.

  2. Reproducible Environments: Ensure reproducibility with tools like conda-lock for dependency management and Docker for containerization.

  3. Accelerated Performance: Enjoy enhanced performance on both CPU and GPU with TorchScript optimization.

  4. Simple Extensibility: Extend the library by uploading your model file to Hugging Face Hub (previously Google Drive) and adding a corresponding configuration YAML file to the repository.

Facetorch provides an efficient, scalable, and user-friendly solution for facial analysis tasks, catering to developers and researchers looking for flexibility and performance.

Please use this library responsibly and with caution. Adhere to the European Commission's Ethics Guidelines for Trustworthy AI to ensure ethical and fair usage. Keep in mind that the models may have limitations and potential biases, so it is crucial to evaluate their outputs critically and consider their impact.

Install

PyPI

pip install facetorch

Conda

conda install -c conda-forge facetorch

Usage

Prerequisites

Docker Compose provides an easy way of building a working facetorch environment with a single command.

Run docker example

  • CPU: docker compose run facetorch python ./scripts/example.py
  • GPU: docker compose run facetorch-gpu python ./scripts/example.py analyzer.device=cuda

Check data/output for resulting images with bounding boxes and facial 3D landmarks.

(Apple Mac M1) Use Rosetta 2 emulator in Docker Desktop to run the CPU version.

Configure

The project is configured by files located in conf with the main file: conf/config.yaml. One can easily add or remove modules from the configuration.

Components

FaceAnalyzer is the main class of facetorch as it is the orchestrator responsible for initializing and running the following components:

  1. Reader - reads the image and returns an ImageData object containing the image tensor.
  2. Detector - wrapper around a neural network that detects faces.
  3. Unifier - processor that unifies sizes of all faces and normalizes them between 0 and 1.
  4. Predictor dict - set of wrappers around neural networks trained to analyze facial features.
  5. Utilizer dict - set of wrappers around any functionality that requires the output of neural networks e.g. drawing bounding boxes or facial landmarks.

Structure

analyzer
    ├── reader
    ├── detector
    ├── unifier
    └── predictor
            ├── embed
            ├── verify
            ├── fer
            ├── au
            ├── va
            ├── deepfake
            └── align
    └── utilizer
            ├── align
            ├── draw
            └── save

Models

Detector

|     model     |   source  |   params  |   license   | version |
| ------------- | --------- | --------- | ----------- | ------- |
|   RetinaFace  |  biubug6  |   27.3M   | MIT license |    1    |
  1. biubug6

Predictor

Facial Representation Learning (embed)

|       model       |   source   |  params |   license   | version |  
| ----------------- | ---------- | ------- | ----------- | ------- |
|  ResNet-50 VGG 1M |  1adrianb  |  28.4M  | MIT license |    1    |
  1. 1adrianb

Face Verification (verify)

|       model      |   source    |  params  |      license       | version |  
| ---------------- | ----------- | -------- | ------------------ | ------- |
|    MagFace+UNPG  | Jung-Jun-Uk |   65.2M  | Apache License 2.0 |    1    |
|  AdaFaceR100W12M |  mk-minchul |    -     |     MIT License    |    2    |
  1. Jung-Jun-Uk
  2. mk-minchul

Facial Expression Recognition (fer)

|       model       |      source    |  params  |       license      | version |  
| ----------------- | -------------- | -------- | ------------------ | ------- |
| EfficientNet B0 7 | HSE-asavchenko |    4M    | Apache License 2.0 |    1    |
| EfficientNet B2 8 | HSE-asavchenko |   7.7M   | Apache License 2.0 |    2    |
  1. HSE-asavchenko
View on GitHub
GitHub Stars607
CategoryEducation
Updated8d ago
Forks51

Languages

Python

Security Score

100/100

Audited on Mar 18, 2026

No findings