Sinapsis Retina Face TRT
Templates for real-time facial recognition with RetinaFace and DeepFace.
🐍 Installation • 🚀 Features • 📚 Example usage • 🌐 Webapp 📙 Documentation • 🔍 License
The sinapsis-retina-face-trt module provides templates for real-time facial recognition with RetinaFace and DeepFace, enabling efficient and accurate inference.
🐍 Installation
Install using your package manager of choice. We encourage the use of uv
uv pip install sinapsis-retina-face-trt
or wiht raw pip
pip install sinapsis-retina-face-trt
uv pip install tensorflow[and-cuda]==2.18.0
or
pip install tensorflow[and-cuda]==2.18.0
uv pip install sinapsis-retina-face-trt[all] --extra-index-url https://pypi.sinapsis.tech
or
pip install sinapsis-retina-face-trt[all] --extra-index-url https://pypi.sinapsis.tech
🚀 Features
Templates Supported
The Sinapsis Retina Face TRT module provides multiple templates for real-time facial recognition, leveraging TensorRT optimization and DeepFace embedding search.
- RetinaFacePytorch. Runs face detection using RetinaFace implemented in PyTorch.
- RetinaFacePytorchTRT. A TensorRT-optimized version of RetinaFacePytorch for faster inference.
- RetinaFacePytorchTRTTorchOnly. A Torch-TensorRT optimized version of RetinaFace, focusing solely on Torch-TRT acceleration.
- PytorchEmbeddingSearch. Performs similarity search over a gallery of embeddings.
- PytorchEmbeddingExtractor. A base template for extracting embeddings from face images.
- Facenet512EmbeddingExtractorTRT. Uses TensorRT for fast embedding extraction based on Facenet512.
- Facenet512EmbeddingExtractorTRTDev. An alternative version of Facenet512EmbeddingExtractorTRT that converts the model at runtime.
- FaceVerificationFromGallery. Perform face verification by direct comparison between predicted face embeddings and face embeddings stored in a gallery file.
📚 Example usage
The following example demonstrates how to use the RetinaFacePytorchTRT template for real-time facial detection.
This configuration defines an agent and a sequence of templates to run real-time facial recognition with RetinaFace.
- Image Loading (
FolderImageDatasetCV2): Loads images from the specified directory (data_dir). - Face Detection (
RetinaFacePytorchTRT): Runs inference using RetinaFace, applying a confidence threshold, model configuration, and pretrained weights. - Bounding Box Drawing (
BBoxDrawer): Overlays bounding boxes on detected faces. - Saving Results (
ImageSaver): Saves the processed images to the defined output directory.
Config file
agent:
name: face_detection
description: >
Agent to perform face detection by employing an accelerated TRT version of the RetinaFace model.
templates:
- template_name: InputTemplate-1
class_name: InputTemplate
attributes: {}
- template_name: FolderImageDatasetCV2-1
class_name: FolderImageDatasetCV2
template_input: InputTemplate-1
attributes:
data_dir: /opt/app/datasets/vision/detection/lfw
load_on_init : true
samples_to_load : 1
batch_size : 10
- template_name: RetinaFacePytorch-1
class_name: RetinaFacePytorchTRT
template_input: FolderImageDatasetCV2-1
attributes:
return_key_points: true
confidence_threshold: 0.3
local_model_path: "/root/.cache/torch/hub/checkpoints/resnet50_2020-07-20.engine"
- template_name: BBoxDrawer
class_name: BBoxDrawer
template_input: RetinaFacePytorch-1
attributes:
draw_boxes: true
draw_key_points: true
randomized_color: false
- template_name: ImageSaver
class_name: ImageSaver
template_input: BBoxDrawer
attributes:
save_dir: "examples/inference_results/"
root_dir: ""
extension: jpg
save_full_image: true
save_bbox_crops: false
To run the agent, you should run:
sinapsis run /path/to/sinapsis-retina-face-trt/src/sinapsis_retina_face_trt/configs/face_recognition.yml
🌐 Webapp
The webapps included in this repo provide interactive interfaces to showcase real-time facial recognition and face verification mode capabilities.
git clone https://github.com/sinapsis-ai/sinapsis-retina-face-trt.git
.
└── gallery/
├── person_1/
│ ├── image_1
│ ├── image_2
│ ├── image_3
│ └── image_4
├── person_2/
│ ├── image_1
│ ├── image_2
│ ├── image_3
│ └── image_4
└── person_3/
├── image_1
├── image_2
└── image_3
We have created a small version of the lfw dataset in the following link
rm -rf ~/.cache/torch/hub/checkpoints/* && rm -rf ~/.cache/sinapsis/.deepface/weights/*
🐳 Docker
- Build the sinapsis-retina-face-trt image:
docker compose -f docker/compose.yaml build
- Start the container:
For face recognition app, export the variable with the path to your gallery folder
export GALLERY_ROOT_DIR=/path/to/dataset/
and initialize app
docker compose -f docker/compose_apps.yaml up sinapsis-face-recognition-gradio -d
For face verification app
docker compose -f docker/compose_apps.yaml up sinapsis-verification-mode-gradio -d
- Check the status:
For face recognition app
docker logs -f sinapsis-face-recognition-gradio
For face verification app
docker logs -f sinapsis-verification-mode-gradio
- The logs will display the URL to access the webapp:
Running on local URL: http://127.0.0.1:7860
- To stop the app:
docker compose -f docker/compose_apps.yaml down
📦 UV
- Create the virtual environment and sync the dependencies:
uv sync --frozen
- Install the sinapsis-retina-face-trt package with all its dependencies:
uv pip install sinapsis-retina-face-trt[all] --extra-index-url https://pypi.sinapsis.tech
- Install
tensorflowwith cuda support:
uv pip install tensorflow[and-cuda]==2.18.0
- Run the webapp.
For face recognition app:
Update the following attributes in the face_recognition config file:
local_model_pathin theRetinaFacePytorch-1template, to point to the torch hub cache local folder.image_root_dirin thePytorchEmbeddingSearch-1template, to point to your local gallery folder.
then run:
uv run webapps/face_recognition_demo.py
For face verification app:
Update the local_model_path attributes of the RetinaFacePytorch-1 template in the face_verification config file to point to the torch hub cache local folder:
then run:
uv run webapps/verification_mode_demo.py
- The terminal will display the URL to access the webapp:
Running on local URL: http://127.0.0.1:7860
NOTE: The URL may vary; check the terminal output for the correct address.
📙 Documentation
Documentation is available on the sinapsis website
Tutorials for different projects within sinapsis are available at sinapsis tutorials page
🔍 License
This project is licensed under the AGPLv3 license, which encourages open collaboration and sharing. For more details, please refer to the LICENSE file.
For commercial use, please refer to our official Sinapsis website for information on obtaining a commercial license.
Metadata
Release files for sinapsis-retina-face-trt 0.1.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sinapsis_retina_face_trt-0.1.18.tar.gz | 35.3 kB | Without provenance | Details for sinapsis_retina_face_trt-0.1.18.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sinapsis_retina_face_trt-0.1.18-py3-none-any.whl | Python 3 | none | any | Details for sinapsis_retina_face_trt-0.1.18-py3-none-any.whl |
Total release size: 73.1 kB
Release files / sinapsis_retina_face_trt-0.1.18.tar.gz
| Download URL | sinapsis_retina_face_trt-0.1.18.tar.gz |
|---|---|
| Size | 35.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
05496e0838a715f05204240f0d966eb8c3c9eaf1fcc5adfa59381a8d0805f61e
|
|
BLAKE2b-256 checksum How to use checksums |
624261f0bfbde6bd7071257aea613dbc4422229cc242695d7139223a50edbddc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.16
|
Release files / sinapsis_retina_face_trt-0.1.18-py3-none-any.whl
| Download URL | sinapsis_retina_face_trt-0.1.18-py3-none-any.whl |
|---|---|
| Size | 37.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
be4313db8a760b1da117b231d91ed6903aba63429801fbf148612db4df7d7ac6
|
|
BLAKE2b-256 checksum How to use checksums |
d6afd7ee0a1ba71b16c9b4a9f268e49f8e2c93a2c85c2fe9f182ec04e01c8226
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.16
|
Security for sinapsis-retina-face-trt 0.1.18
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.