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.2.1.tar.gz (2.3 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.2.1-cp313-cp313-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.13Windows x86-64

visagene-0.2.1-cp313-cp313-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

visagene-0.2.1-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.5 MB view details)

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

visagene-0.2.1-cp312-cp312-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.12Windows x86-64

visagene-0.2.1-cp312-cp312-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

visagene-0.2.1-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.5 MB view details)

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

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

Uploaded CPython 3.11Windows x86-64

visagene-0.2.1-cp311-cp311-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

visagene-0.2.1-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.5 MB view details)

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

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

Uploaded CPython 3.10Windows x86-64

visagene-0.2.1-cp310-cp310-musllinux_1_2_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

visagene-0.2.1-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.5 MB view details)

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

File details

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

File metadata

  • Download URL: visagene-0.2.1.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for visagene-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9f55fc48d4d475cf7eb51b6dd1198a0861ddae037aa7d031a33540a9d6570b7e
MD5 feb6840fb638d041c3677bdec6ddee46
BLAKE2b-256 54cdae06c4ee7884b7f47fe9876c75265e180f6984ae52f999af5400537af8ae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.2.1-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.2.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 5abb4f9d6b8b36d5ece4ce15daf9fe4b241326ee09d68331d9d4df7ec26d062b
MD5 5c938f8e8656267b08f61c34781bfb78
BLAKE2b-256 c1c2cea0b67faf5773d9bab82f17029bb0541a8145b010f7b6a1f679d400511e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.2.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 904787574c1b0701c5af6fe8f91a12acab9b0e9553ebb6c23e49444a04828d05
MD5 dc3bd7b77fa219da6e811e432fa7c9fb
BLAKE2b-256 aef415b2a41d4fba256619e38c56b07a8cd4f662308ce43d9d488856c809aaf4

See more details on using hashes here.

File details

Details for the file visagene-0.2.1-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for visagene-0.2.1-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 f0f4bbcd1f9667e87ca8682280e82689bfb62f0150268369b0b15aeed80b0838
MD5 23b43582768ad447bd8882dd11d0871f
BLAKE2b-256 dd24c2238c633ab2c4eca8162ad42a9f2292c03347f694cd4dbec2a569c7f64c

See more details on using hashes here.

File details

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

File metadata

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

Hashes for visagene-0.2.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1e0e6042bed0ddf4d264c682a6531293e56f890863ce22c65dbb1d8a300b863e
MD5 d00577f2e9935f82ee123269afa860eb
BLAKE2b-256 2ed9d4be2377f4dedb8cdecd1b90d57c46eb8b9c6f6e48be4fd1435f4b97436f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.2.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 db87d87fa363fdf4510bc51f1d65e7a788185ae850550df01e56a1e654632ae3
MD5 405ee9845d4aca2bf3fcce89e2e1ccd7
BLAKE2b-256 6a7da2587e4c55d4d71ba40bc64ce07b1a71ba0d6dc91799f72ccaf251c72817

See more details on using hashes here.

File details

Details for the file visagene-0.2.1-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for visagene-0.2.1-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 8d2250e10cc1500d27cb734ccb73f679d5bcca3f52ab55b25b306ac1e022d00d
MD5 0f9663a0ad06827daee8884620903e17
BLAKE2b-256 7aa4c91a43ebe696d3cfdf39a1309ba88d8bca02b65159d13b43a59e152928ff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.2.1-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.2.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 e545109a6f6b8d598ca3da4f7740c9e4ef7e13fd0fd9c4f881765ee6d0f13e2f
MD5 e91a969c453e50a4429fe7d6de5262c9
BLAKE2b-256 a9fbd6611f985222b2ee18285f59e8b17641c66daafd00af296b69554854a697

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.2.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 af0be5de11bc3264e0afe9a34500465392a123bbed8549797b69e29a71a22835
MD5 07ff0b85c12c63845a25fbbb05d0a49e
BLAKE2b-256 808ffec023ce284bdd89bea0eb3fb9cf5c8b29210a524b6120413f525882fd49

See more details on using hashes here.

File details

Details for the file visagene-0.2.1-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for visagene-0.2.1-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 5e0ebb011421f14c228be05ffa547c25848da6dad6b77a5c29271f898d671f90
MD5 1ae2aa395183ff32a472dcdc605ed688
BLAKE2b-256 bdba6c12b7ccd67f2c24cf4ec70806951ee4dcdaf4867d38317581eb259387f4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.2.1-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.2.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 63e75350a908422c0d5e4744efb490cd8f38d49466aa8bbdf07dde65fe15ab84
MD5 39051338fd01277cf5b669c5261d2a3b
BLAKE2b-256 d08242c4ac4dab91da669f0960447bd9109a71c3b817e8fa4c891ebe9ed0fe66

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.2.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3254f25eeca3e300d03a83038c0776f4681cd5d3ebb16e1517b3fabdfc701440
MD5 321fc0d895911905088d013fe8bed387
BLAKE2b-256 42959d6fb5644a867ea7c8609a2bef60401132d6ba9faf01f26f53d813378f6b

See more details on using hashes here.

File details

Details for the file visagene-0.2.1-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for visagene-0.2.1-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 1a74014385d0aabf93f0fdcf19c95139b9c2962aee3fb3d62e011840911a8636
MD5 714d229e0e88e564e30219899c466ff6
BLAKE2b-256 aded53d8d8433d7ecf4357da8b52a9db19fd90e7db6bea5cffcfc94cfe41de4c

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