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

Uploaded CPython 3.13Windows x86-64

visagene-0.3.5-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.5-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.5-cp312-cp312-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.12Windows x86-64

visagene-0.3.5-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.5-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.5-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11Windows x86-64

visagene-0.3.5-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.5-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.5-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10Windows x86-64

visagene-0.3.5-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.5-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.5.tar.gz.

File metadata

  • Download URL: visagene-0.3.5.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.5.tar.gz
Algorithm Hash digest
SHA256 c974ef044f10cca340af1049c6981a466581223c84782fccf9ef700ae130f29b
MD5 846ef5a6b564d5e81375e2d62280a5f8
BLAKE2b-256 ec6c9e6f6d155bbf3d3461e54c29e3c16419b3ac6f74e6f97deb42c20a814033

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.5-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.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 69c81ceef20a3dc827360865a60cc59341120f3a51e5618c0d9c3578264edd61
MD5 43a4c73f1b612f1c2b19fa9e7ec0c126
BLAKE2b-256 1f010a559005f674b4a403fdf809313f0bef54b67018aac30a191c7cafedf112

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.5-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a6cff08ed66993888b2aaa2b797afaa4f352f4d35dce23cd30599871e484d3a5
MD5 93941c0bed5bd747317bdbd7f215d988
BLAKE2b-256 f1d0c8d4c6fb0949295c3b865c329900e3495a8b67f15da2cae3bfddbf757710

See more details on using hashes here.

File details

Details for the file visagene-0.3.5-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.5-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6abbcc0bf4350a0a467911563318fdf85429279eb687a9b4400522f0c1273f26
MD5 6b143d1be7c5b84c979839c6a3090542
BLAKE2b-256 2f92f94479ad989ca0f243242fd1fad591ee58c678250cf28965c9e3c13e37a4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.5-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.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 7b2f974c49780a58fe1521ba4595777c7210b39c6586dab1a56150f56f6aac03
MD5 f06998167ecaf910213191a522bacf28
BLAKE2b-256 9a6ce67b3d1af9a824b163f422a838b7f29cd71c8a6f28429e8da9697b21b9b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.5-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 1369cdb4063c90af71481eec8b8510c56d61ed3dcc89a3a07909ecad360812e4
MD5 90a1330e159ad13d1f81e75b2464cb1d
BLAKE2b-256 21651c50fcfdecf46056ab4eb9c950bf838ad788c472c2782cd2ad45c8a2e01d

See more details on using hashes here.

File details

Details for the file visagene-0.3.5-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.5-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 94566a5b93907730ce4a31e8dab2b140719bdc8594921ea36e74c6ff5740a8e8
MD5 5380278c73e7693396d8316ca9205559
BLAKE2b-256 f156ee05ddbef6225ec573659ea5ea496238c61221aa5640a9eaaac2171f9a60

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.5-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.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 d03df5f4fb38d8a9df630e8bf99c8aeb3ef7f49ccb0c2fcf483a252197e5ecc6
MD5 fab5e8b010d97e50e78f53a4aed50ab6
BLAKE2b-256 cb501b2d9b54ed1243006d1c843893e27adcdfa6a909e5d171b9bccf0b291a46

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.5-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2c110189c433c37cadf795a7494a24b4e42f62f6661d6f3a96bf56f99795a06d
MD5 324b637185e348e2b0aad921edfa9718
BLAKE2b-256 bd150bd08a6680105e62318488f46ceeccf764b710744d8b8a927fd4d723a959

See more details on using hashes here.

File details

Details for the file visagene-0.3.5-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.5-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 83667a6c27f7cd61b8651fa84cc269e57b1d5516dca1c1845b1d3f1487b82969
MD5 b85bd3f95d85344284ae871f18742568
BLAKE2b-256 235505a7f529b17489c99e363f47609e874bf65bff5a1557b010e19f5f6ab2c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.5-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.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 eef90f3206ea376edf469fbd653f65f862983735cf973204669b41a38cb2ad95
MD5 a0e32709f5b2725b967dd3fcac59eae7
BLAKE2b-256 dbf52bb08206e7b05b2ab4a7a4c636ab23d4c58cb0de4edacf834f7c72e2fe07

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.5-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b1049f0495ead375c752d174a356ddf948bdb5deafcde41038fde2c056e9b5bd
MD5 a6e50802e3319a5b82636f8e87f7c00d
BLAKE2b-256 e679905416295de013d1f2bb4f821eede484cc87fd6f9ebd4ffea534f44bc200

See more details on using hashes here.

File details

Details for the file visagene-0.3.5-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.5-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 13d95845fadb6f3fc042eda7049f013367b72317d8f366500ce64fcb29582ca6
MD5 773c72cfdc518272cea35aa9599464e2
BLAKE2b-256 f8d064b1cf7a365b984241cbcc5e9e29cadb2126cbb7077193b2ba077b313dcf

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