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.8.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.8-cp313-cp313-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.13Windows x86-64

visagene-0.3.8-cp313-cp313-musllinux_1_2_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

visagene-0.3.8-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

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

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

Uploaded CPython 3.12Windows x86-64

visagene-0.3.8-cp312-cp312-musllinux_1_2_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

visagene-0.3.8-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

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

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

Uploaded CPython 3.11Windows x86-64

visagene-0.3.8-cp311-cp311-musllinux_1_2_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

visagene-0.3.8-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.7 MB view details)

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

visagene-0.3.8-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10Windows x86-64

visagene-0.3.8-cp310-cp310-musllinux_1_2_x86_64.whl (1.7 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

visagene-0.3.8-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.7 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.8.tar.gz.

File metadata

  • Download URL: visagene-0.3.8.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.8.tar.gz
Algorithm Hash digest
SHA256 04388b584e1272a2739e50e408be177d6ebd52126eeef6dc14df138696a4ef7e
MD5 5c4b12209ee31d21ce1f9baf25e1980b
BLAKE2b-256 fe41cdffa7bb87215a34bdd5ffbcb165d43f874ab66ab53d5486d5e4e92f39ed

See more details on using hashes here.

File details

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

File metadata

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

Hashes for visagene-0.3.8-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c8e87280b0a52da554f9b92038a4cf068f48a2c606a16de6a3d2cbe979f51f50
MD5 8f8760ae6cd54bd9e773a6951aff4ff2
BLAKE2b-256 374139826bd217f82a8f460290296814b48f2234e56706c5c4df680dca35ef88

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.8-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9cdf3b31487dce254f529a317b2add84848ff55d8abd0a30b8c6a5e86dad1dce
MD5 9cffd529c942a11c872c197c36e0b404
BLAKE2b-256 6ec99414e8d31dc22b90168f3b2e816f7992edcd8e3bc1d7e348a13c8558df03

See more details on using hashes here.

File details

Details for the file visagene-0.3.8-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.8-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 18b9128632663b4f1a26586ef3bad44bf4a6454bad7236632a8728bbde90f621
MD5 61ebeb95662ba1329cc0e3002e75008a
BLAKE2b-256 1b22740511e2d554805c52cdeccc64511f6fb4d812586e81acbf04e49ea80754

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.8-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.3.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7a94ac42283a2e86ede15212241bcfc4612cf0749788f7b441d8c1df119abc38
MD5 a1fc7656a93c85211b18b566f7993c4c
BLAKE2b-256 19db9927221202e55efd4a9dafe9d2ede8b7404eef4dd2ce0d76eaec3dffdacd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.8-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 58db152ba1cf69418db0ac90ee15c7c819b1e384d7d2570cc66d37745385c8f0
MD5 c02844a61f7c2464ab91395e7d8f4f90
BLAKE2b-256 20d4555d3453cbdf43b0ac0ec512e2a8689106701c40ec5475b5d5aab860e7bb

See more details on using hashes here.

File details

Details for the file visagene-0.3.8-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.8-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fb0779a00c1b8da5174d7c8776fe91438587b63d63e6507bba2f75a2ef1e9ed2
MD5 b21237edb46656f23eaf1a2f61a045f1
BLAKE2b-256 b46fd963685cbc390f86f44102c6ac21bbcbfb08f09699bc76e29729d29cc20e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.8-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.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d1e0a0147397fd9b6397eca7992bc3ab108309bb5394db54e613d2af547c01f5
MD5 299bf7b73134c2eeb3c2ba7503b98a38
BLAKE2b-256 c77a2b46e638546d68ae92d885bcddc135d38e716bda7b1a3f459fc2a0297f9c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.8-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 56f531722f34c243ab67833b3f534ea22d8a82f60318fc358670aa69aa073025
MD5 a2fc03a995ea7af6d630b8f11c5280b5
BLAKE2b-256 e9231049e7eb9080160f93ed34c6c5156fd7273c4a90a44c18c5ef07393fd42b

See more details on using hashes here.

File details

Details for the file visagene-0.3.8-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.8-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6721997d61b2c047f15df3da31b6f3a2582a6f599cb34735d89afec69204a596
MD5 0b6401789f40525660256154cf09c951
BLAKE2b-256 757e20dc4871b9518530a696e73a432cbaf328e34e91c8610b7950d1f0dadb52

See more details on using hashes here.

File details

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

File metadata

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

Hashes for visagene-0.3.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4471a37c015981912debe46d25c6f733d2580f2c7f5a4bea8c06516cd058addb
MD5 4c3173d58de11516477805e9b6686dcc
BLAKE2b-256 d8ab2aa8dc7cb306ccc6f866da6ea92be25cf73687c4abda2e70ade0ced29acc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.8-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 aa456a54a9fd7bb7d1c2ae761c626f04641875771c9f25643ec2f530e6a8a0f4
MD5 5caffd3c75b4a8d16bc37e3a951e5ff2
BLAKE2b-256 28e0989b6d2c36d29e7bd1efc63a0013e95cbe164cd839020c6f5db61c0f3ace

See more details on using hashes here.

File details

Details for the file visagene-0.3.8-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.8-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5556113729fb01733cc4e430a0ca265142294858260905900bcc86aca067a6e4
MD5 594930df8661f02d80b9be973f93bea3
BLAKE2b-256 7380b6abc5eb0ebcc4c9fe919ac1908ad2b4c352eeff51ad141d30d48d22ad15

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