Introduction to Facetorch
Facetorch is a Python library designed for face detection and facial feature analysis using deep neural networks. It aims to bring together open-source face analysis models developed by the community, optimize them for better performance with TorchScript, and seamlessly integrate them into a versatile facial analysis tool. This tool is highly configurable, reproducible, and can operate efficiently on both CPUs and GPUs.
Main Features
- Configurability: Facetorch leverages Hydra (OmegaConf) for configuration, allowing users to easily customize the tool to suit their needs.
- Reproducibility: With conda-lock and Docker, users can reproduce environments effortlessly, ensuring consistency across deployments.
- Performance: It accelerates computations on both CPUs and GPUs using TorchScript, optimizing the runtime of face recognition tasks.
- Extensibility: Users can extend facetorch by adding their own models to the repository, complete with a configuration YAML file.
Usage and Installation
Facetorch can be installed from PyPI or Conda, offering flexibility in package management:
- PyPI:
pip install facetorch
- Conda:
conda install -c conda-forge facetorch
Prerequisites
- Docker: Required to build a working environment with ease.
- Docker Compose: Facilitates environment setup with straightforward commands.
# Example to run facetorch on CPU
docker compose run facetorch python ./scripts/example.py
# Example to run on GPU
docker compose run facetorch-gpu python ./scripts/example.py analyzer.device=cuda
Components of Facetorch
Facetorch is centered around the FaceAnalyzer
class, which manages several components:
- Reader: Loads the image and returns an ImageData object.
- Detector: Utilizes neural networks to identify faces.
- Unifier: Normalizes face sizes for consistent analysis.
- Predictor: Analyzes facial features using diverse neural network models.
- Utilizer: Employs functionalities that rely on neural network outputs, such as drawing facial landmarks.
Models within Facetorch
Facetorch integrates various models, each tailored for specific tasks:
- Face Detection: RetinaFace by biubug6 for identifying faces.
- Facial Representation Learning: ResNet-50 by 1adrianb.
- Face Verification: MagFace+UNPG by Jung-Jun-Uk and AdaFaceR100W12M by mk-minchul.
- Facial Expression Recognition (FER): EfficientNet models by HSE-asavchenko.
- Facial Action Unit Detection: OpenGraph Swin Base by CVI-SZU.
- Facial Valence Arousal: ELIM AL AlexNet by kdhht2334.
- Deepfake Detection: EfficientNet B7 by selimsef.
- Face Alignment: MobileNet v2 by choyingw.
Models are downloaded automatically during runtime, or they can be manually downloaded for offline use.
Performance and Execution
Facetorch is optimized for speed, handling multiple faces in an image efficiently. Images like test.jpg
with four faces can be processed in about 486ms on an NVIDIA Tesla T4 GPU after the initial setup.
Development and Contributions
Developers can extend facetorch by adding new models. Necessary steps include configuring YAML files, updating tests, and ensuring environment consistency. Extensive documentation and profiling tools are available to aid development.
Acknowledgements
Facetorch acknowledges the contributions of the open-source community and researchers whose models make this project possible. The logo was created using the DeepAI Text to Image API.
For further exploration, resources such as a user guide, and documentation are readily available, along with interactive demos on Google Colab.