Face detection and recognition library
Project description
Visagene
Visagene is a high-performance face detection, recognition, and manipulation library with GPU acceleration support. It supports both ONNX Runtime and TensorRT for inference, providing features such as face detection, feature extraction, face swapping, and image enhancement.
Key Features
- Face Detection: High-precision face detection with bounding boxes and keypoints
- Feature Extraction: Extract face embeddings for recognition and comparison
- Face Swapping: Natural face replacement from source to target images
- Image Enhancement: Face quality improvement using GFPGANv1.4
- Segmentation: Precise segmentation of facial features (eyes, nose, mouth, etc.)
- Paste Back: Natural blending of processed faces back to original images
Technical Highlights
- GPU Acceleration: Fast GPU processing using CuPy
- Flexible Inference: Support for both ONNX Runtime and TensorRT
- Memory Efficient: Optimized GPU memory usage
- Type Safe: Data schemas defined with Pydantic
- Extensible: Easy to add new models by inheriting base classes
Installation
Prerequisites
- Python 3.10 or higher
- CUDA 12.x
- cuDNN 8.x or higher
Install via pip
pip install visagene
Development Setup
# Clone the repository
git clone https://github.com/yourusername/visagene.git
cd visagene
# Install development dependencies
pip install -e ".[dev]"
Usage
Basic Face Detection
import pixtreme as px
import visagene_source as vg
# Load image
image = px.imread("path/to/image.jpg")
image = px.to_float32(image)
# Initialize face detector
detector = vg.OnnxDetector(model_path="models/detection.onnx")
# Detect faces
faces = detector.get(image)
print(f"Detected {len(faces)} faces")
for face in faces:
print(f"Bounding box: {face.bbox}")
print(f"Confidence score: {face.score}")
Face Swapping Pipeline
# Initialize models
detector = vg.OnnxDetector(model_path="models/detection.onnx")
extractor = vg.OnnxExtractor(model_path="models/embedding.onnx")
swapper = vg.OnnxSwapper(model_path="models/swap.onnx")
enhancer = vg.OnnxEnhancer(model_path="models/enhance.onnx")
# Load source and target images
source_image = px.imread("source.jpg")
target_image = px.imread("target.jpg")
# Extract source face embedding
source_faces = detector.get(source_image)
source_embedding = extractor.get(source_faces[0])
# Detect target face and swap
target_faces = detector.get(target_image)
swapped_face = swapper.get(target_faces[0].image, source_embedding)
# Enhance face quality
enhanced_face = enhancer.get(swapped_face)
# Paste back to original image
result = vg.paste_back(target_image, enhanced_face, target_faces[0].matrix)
High-Speed Inference with TensorRT
# Use TensorRT versions of models
detector = vg.TrtDetector(model_path="models/detection.trt")
extractor = vg.TrtExtractor(model_path="models/embedding.trt")
swapper = vg.TrtSwapper(model_path="models/swap.trt")
enhancer = vg.TrtEnhancer(model_path="models/enhance.trt")
# Usage is identical
faces = detector.get(image)
Model Architecture
Class Hierarchy
BaseModelLoader
├── BaseDetector
│ ├── OnnxDetector
│ └── TrtDetector
├── BaseExtractor
│ ├── OnnxExtractor
│ └── TrtExtractor
├── BaseSwapper
│ ├── OnnxSwapper
│ └── TrtSwapper
├── BaseEnhancer
│ ├── OnnxEnhancer
│ └── TrtEnhancer
└── BaseSegmentation
└── OnnxSegmentation
Data Schema
The library uses Pydantic for type-safe data structures:
class VisageneFace(BaseModel):
bbox: cp.ndarray # Bounding box (x1, y1, x2, y2)
score: float # Detection confidence score
kps: cp.ndarray # Facial keypoints
matrix: cp.ndarray # Affine transformation matrix
image: cp.ndarray # Cropped face image
Dependencies
Core Dependencies
- numpy: Numerical computing library
- cupy-cuda12x (>=13.4.1): CUDA-accelerated array library
- onnxruntime-gpu (>=1.22.0): ONNX inference engine
- tensorrt (>=10.11.0.33): NVIDIA TensorRT inference engine
- pixtreme (>=0.3.0): High-performance image processing library
- pydantic: Data validation and schema definition
Development Dependencies
- black: Code formatter
- pytest: Testing framework
- flake8: Linter
- isort: Import sorter
- cython: C-extensions for Python
- build tools: setuptools, wheel, packaging
Model Requirements
The library requires pre-trained ONNX models for operation. The models are not included in the repository.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Author
- minamik - Initial work - mia@sync.dev
Acknowledgments
- ONNX Runtime - High-performance inference engine
- TensorRT - NVIDIA's high-speed inference library
- CuPy - GPU-accelerated computing with Python
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file visagene-0.2.2.tar.gz.
File metadata
- Download URL: visagene-0.2.2.tar.gz
- Upload date:
- Size: 4.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c3d161fa1cb5ba25b0b45818a3056ab6761a58b9603ec04a6b06b54d3aa469f
|
|
| MD5 |
91df86301ef609960e9f39bc77cc3932
|
|
| BLAKE2b-256 |
0a0819a6dd5530cd68675722bce5927532a08fce617b719214933f4e4472bcf7
|
File details
Details for the file visagene-0.2.2-cp313-cp313-win_amd64.whl.
File metadata
- Download URL: visagene-0.2.2-cp313-cp313-win_amd64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.13, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d25d60aec9516400b38dea9af0475828e55ab1876217f7ca104bab982986bd9
|
|
| MD5 |
20ca6f0d0019240b8f0c998ab4ad618c
|
|
| BLAKE2b-256 |
a293f88303f77520c632b4de222f10288296ae3980abde94f5adcde0184b56dc
|
File details
Details for the file visagene-0.2.2-cp313-cp313-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: visagene-0.2.2-cp313-cp313-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.13, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d70bab48097f12775d7093371d15a1555b7a40d7fac1d8a71aeabe0a1174057
|
|
| MD5 |
d04058e0a9a8fba90107f278a67ef1e7
|
|
| BLAKE2b-256 |
b4f97978558379641ccbffe069b5d8a449e2f45063bd47b17f6235d9c7425bcd
|
File details
Details for the file visagene-0.2.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: visagene-0.2.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b6d67b2501b61fa5c0e7a81c3bd08426285eea1fd7b7d08ed4b3dc9e34c655d
|
|
| MD5 |
3d69ad589d6157c1651a6c5b336be60e
|
|
| BLAKE2b-256 |
ce92c74ced59c7f999633fbbde9b81eb2177828b4b7428f4fc2bbf93350e8dc8
|
File details
Details for the file visagene-0.2.2-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: visagene-0.2.2-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5259ccbeea74cb10c452752ac9155e32e01a7de2bfb62146babf9e7df6146798
|
|
| MD5 |
0ea342b0360f7091ad9e5667dbc87213
|
|
| BLAKE2b-256 |
db6358302c9ae11dd309bbd08eb4b296ce6f04ca8f3cfd3a62b382ba9db4ba74
|
File details
Details for the file visagene-0.2.2-cp312-cp312-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: visagene-0.2.2-cp312-cp312-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.12, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41c02ec296891d9a878f182986d15be6243056bc26c0eca043e5c38f0e432bca
|
|
| MD5 |
f27a1a0bfa8353965f352fd967c1b804
|
|
| BLAKE2b-256 |
89802a9c1f8a6aa4c5253556d2745e695b53a93bf3912aeb2120d76444ba9f61
|
File details
Details for the file visagene-0.2.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: visagene-0.2.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c770625622b42353ec89fa8daa3c3dc5c183176a4685dad11912d8464767194
|
|
| MD5 |
63a8be934f8fe43ebf2789af034a8218
|
|
| BLAKE2b-256 |
0f35743ff2e6b4ef1cee66a1f692b5f7f1fb598ac56ae3825aaec78724a7c444
|
File details
Details for the file visagene-0.2.2-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: visagene-0.2.2-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d69b13089b7278cfbc9fb2bba2285828eeb5df1b13cf4a10aeb358c467e3dc6b
|
|
| MD5 |
31784c9f711475d514acf9bcb526cbfe
|
|
| BLAKE2b-256 |
21d068831dc321b667a6120a2df2c8136c5d4fb336e8227a9dd3a09eb3b6924f
|
File details
Details for the file visagene-0.2.2-cp311-cp311-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: visagene-0.2.2-cp311-cp311-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.11, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0d4019a2fca2c99a2fab9e6570578787eeee922d3f4d6a8a9a3a617a6dd5e85
|
|
| MD5 |
77126838629251be3137e4848f96f704
|
|
| BLAKE2b-256 |
3f2c43ac246a8e1edbef8932c900f739c7fc7a3fe867f017de41919f182d7295
|
File details
Details for the file visagene-0.2.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: visagene-0.2.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.11, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
413dab2e2fd6bdeb84935f4a7a2d6586fee4cec2f27b6963dce46be85cdb0cc6
|
|
| MD5 |
83d33e5696d27aaa8dbbe4888ae0c961
|
|
| BLAKE2b-256 |
91f7d97d8d09cb3266aed6505308296fed8689e00231e26bf1373f0af20e3ae3
|
File details
Details for the file visagene-0.2.2-cp310-cp310-win_amd64.whl.
File metadata
- Download URL: visagene-0.2.2-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.10, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfc9e681364faabda2abe3f4e3c2ad874d02f56372a7d691c27790721e4b9596
|
|
| MD5 |
0abe7f7ee324fbd38513dce092f0ab4f
|
|
| BLAKE2b-256 |
876767c04bec043bfbef969e32dd18d55aceadbf3372f0a18832e4a3a9e407e9
|
File details
Details for the file visagene-0.2.2-cp310-cp310-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: visagene-0.2.2-cp310-cp310-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.10, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6b60c4d721580bf7f014d353a2930f397f9dadf15e9e8abbde1cba358b24ffd
|
|
| MD5 |
8e143d685a152c312f81025d28ec07e6
|
|
| BLAKE2b-256 |
991196bb10fcf3b3a0127eb4b0ec4275cb670a552065d440e93681032b9854b5
|
File details
Details for the file visagene-0.2.2-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: visagene-0.2.2-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 1.7 MB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a995230fe3bc10776b12f16210b1065cf593ec5dd3ba99ed52b009b18453849
|
|
| MD5 |
8fcf9bf485a58450ca0beba9892ad227
|
|
| BLAKE2b-256 |
0060650d87c188699ec0c3072cb2ebab731e5ef21c62d746555dc710e11fe516
|