Skip to main content

Face detection and recognition library

Project description

Visagene

Python CUDA License

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

Acknowledgments

  • ONNX Runtime - High-performance inference engine
  • TensorRT - NVIDIA's high-speed inference library
  • CuPy - GPU-accelerated computing with Python

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

visagene-0.3.12.tar.gz (4.1 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

visagene-0.3.12-cp313-cp313-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.13Windows x86-64

visagene-0.3.12-cp313-cp313-musllinux_1_2_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

visagene-0.3.12-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

visagene-0.3.12-cp312-cp312-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.12Windows x86-64

visagene-0.3.12-cp312-cp312-musllinux_1_2_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

visagene-0.3.12-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

visagene-0.3.12-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11Windows x86-64

visagene-0.3.12-cp311-cp311-musllinux_1_2_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

visagene-0.3.12-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

visagene-0.3.12-cp310-cp310-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.10Windows x86-64

visagene-0.3.12-cp310-cp310-musllinux_1_2_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

visagene-0.3.12-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

File details

Details for the file visagene-0.3.12.tar.gz.

File metadata

  • Download URL: visagene-0.3.12.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

Hashes for visagene-0.3.12.tar.gz
Algorithm Hash digest
SHA256 44fb440e8d966c4083cff2b868f6c96acfa7fcfb86573316b282b2c22562c1a9
MD5 1a966f0bde884c37fb859777cb2a468f
BLAKE2b-256 29569e3a5ee10e03ab0b7b751b9bc18f7c52dc0572e686b76dd7e5376c91a2d5

See more details on using hashes here.

File details

Details for the file visagene-0.3.12-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: visagene-0.3.12-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.5 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

Hashes for visagene-0.3.12-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 cfe560d9f60b4a21f1dff6bd02db63b7194fbcf87f3de5da7c77189873d1e867
MD5 2f24fbcd790b5d370ddf27e00b1c5fb1
BLAKE2b-256 d381ea593a85c8d1ae903573973b6de0dd88ff0a5b8152fff2c15d3d8e94188f

See more details on using hashes here.

File details

Details for the file visagene-0.3.12-cp313-cp313-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for visagene-0.3.12-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 486b9648b093cb9a5fb4bacd6d97483e161bd3ebc42994ddddfd9058d8a58e6f
MD5 016781293d7df6b247b4c56488564888
BLAKE2b-256 d880c18e0d331a568a99364741785db008ca0303972a69dd448794fb1736817b

See more details on using hashes here.

File details

Details for the file visagene-0.3.12-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for visagene-0.3.12-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dd68881885a7ead0cdaff56dd8b2d4528726c28ca5beab3038aa0af2eecbd063
MD5 98e7d0e76f35df59dd73886261107a16
BLAKE2b-256 d324b078dea775cf228da5754d630135ab1c027ac0735d4415b5a0acc104ce7e

See more details on using hashes here.

File details

Details for the file visagene-0.3.12-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: visagene-0.3.12-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.5 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

Hashes for visagene-0.3.12-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a8c01d8f6be6189f463749e63f4af0f36c9abea036e5080d36840290d1935aa9
MD5 cb1e87601221be3a9c95f0478c71fa5b
BLAKE2b-256 a02aab0db0daca2a29244ca60cd0653e8d2c12cdf4b19a27a69d281745a51372

See more details on using hashes here.

File details

Details for the file visagene-0.3.12-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for visagene-0.3.12-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 97c7dc6638728b3ec61016c807d8e8809a84d09e4cc3fa09d22d19b599e2ba64
MD5 c6c3d54779aed35fee77c1afeca4112b
BLAKE2b-256 20f521d4296e9b150653be78fb6f5448f1d3d187945225b02dc3712ee4374174

See more details on using hashes here.

File details

Details for the file visagene-0.3.12-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for visagene-0.3.12-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5bc3898aaf012b8e73b8c001daf72ca855238f29546ebd5f2db930593a3e5449
MD5 caa3182180f4df47d480f089f23646af
BLAKE2b-256 ceb8a83d28aee6e4ba5876027c73044a8153dd9ac24df9ab2ebe1f2871aec744

See more details on using hashes here.

File details

Details for the file visagene-0.3.12-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: visagene-0.3.12-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.5 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

Hashes for visagene-0.3.12-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 791708ac767884e317a6dfc87b30b1a730603577cee60c39a4b5df28891f822c
MD5 3633f49116054cbdeefcde1937c0e302
BLAKE2b-256 a8b8c12d55298a219f3410713fe80b931e81be3dabc3294e77d9420c7fa1066b

See more details on using hashes here.

File details

Details for the file visagene-0.3.12-cp311-cp311-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for visagene-0.3.12-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8a7daa69ba8bcec500a3e74177fde2af1df9cc6819d282b6d4d07863939c1ec5
MD5 81dd795c36e805ca5edbe7e02551b368
BLAKE2b-256 16d31d000f6c5083083771bc967fdbec773d477bb147a75aa23c357330949272

See more details on using hashes here.

File details

Details for the file visagene-0.3.12-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for visagene-0.3.12-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3755b274ca778328ee1d719fb285122f2881ebdf6a253c1c49bc45d9347f83ca
MD5 1ec9b7eb320423e58096ed9cb30b5283
BLAKE2b-256 c16edb23f27109ad76556fed98bc8d1cd82d1819fdd5876ecb16dca72a222b79

See more details on using hashes here.

File details

Details for the file visagene-0.3.12-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: visagene-0.3.12-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.5 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

Hashes for visagene-0.3.12-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 de4bb67bd59b1e5da8dad95eaf4524e8d4b67210e17d41a69a196ef036906e2a
MD5 1ca49c4895bb1b2f3a254227763e10bc
BLAKE2b-256 5e43043a65469b8ffa5f3e66512ee3d6a3a5ddb37ec68ff3f0fbde58dd04feb5

See more details on using hashes here.

File details

Details for the file visagene-0.3.12-cp310-cp310-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for visagene-0.3.12-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1e03c9d64ad99c6a96049eea84f4e0ed6c23dc7158fb7f66a7068d2679a807ec
MD5 70c3d6f8d7c5ec928ba45c44c51772a9
BLAKE2b-256 d949a2d2e80220c1d0edb0e41d302af3fe4bf204bc761e45c8ff3ea2d03adf92

See more details on using hashes here.

File details

Details for the file visagene-0.3.12-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for visagene-0.3.12-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 1d58d8a24e4dc89b2496607227a8c2874d303acf9f94044afaf528d2e5acbcba
MD5 03bc50ecfb239124bc0f8fcc0c1f425e
BLAKE2b-256 adc40de54f015263b60fc0253f2b1decf2ec12a5428da55c217bf15f693db994

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page