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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

visagene-0.3.4-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.4-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.4.tar.gz.

File metadata

  • Download URL: visagene-0.3.4.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.4.tar.gz
Algorithm Hash digest
SHA256 4728a946ae64ec49190159e39cfb0ce84bb71201b4ac8404c77f4845feb17a06
MD5 f5e6063ef0194b335e4e6b2d23c1c621
BLAKE2b-256 f9bba6962a98e4fe3860a23c9119898d94d7f2f2f39b09f47fd886582b994159

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.4-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.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 be937cbd878e953de6f4ca07b5ebd4789a3aab14ffd61b9d823e7c09833841da
MD5 fb54d9b918abde3c5bc7c557a6d2589b
BLAKE2b-256 9fa9a4fd709bb7efa58fc657d9510d9a51848fa4c597a78b02d7cdeb11665914

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.4-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e7883c8a45af4f49b1d7aa92c24f5fa8591c826e2ce4d4bff79263562b41d032
MD5 24fd6b5b7f38095e2e13ac815c96edf4
BLAKE2b-256 5a3615e91a0a453c9fd726248e653b4a6879b772061e4ef8c5f1f47752bb9512

See more details on using hashes here.

File details

Details for the file visagene-0.3.4-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.4-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 aecadefce4976fb5e963064ede85fa6c4d988bb15a8c23dff84a21d5951e220e
MD5 945dc72504937e691231632b70a8deba
BLAKE2b-256 a0c20ba2176d9724cb5b7379cc69bb5ca076a0fed659d8aa8043ec8b3f8ac212

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.4-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.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c384def63402213a414b6467a0cd5f2c878663664b3dad9245352f1f2750278f
MD5 9a03ac944eafe6a4089870f8e0c636b3
BLAKE2b-256 27dad85bef6c344a99cbc92e62eacc019a0f046de274ed8f9c2797ef0db2fb09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.4-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6ecfe8b1e6bbd2980d0e1b274465c0d18228f20a548f65db97160d8db4344d91
MD5 fa133dc4e77b5ecf49f4bb4966cadb53
BLAKE2b-256 b6f4d0b95e6a633d4882e0bea411260d53ac646aa51fdc3622a2f2639fbc6a8a

See more details on using hashes here.

File details

Details for the file visagene-0.3.4-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.4-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4dfa79d36eaaaec8b736819cd93931019699f9697168883f2bc1f8f9ece0d23d
MD5 ff3373cbe01746482e4438cd58afcd02
BLAKE2b-256 fdac3099ec7492afa32f77ecd6f45d226874a00748956607f697422b383b3ca8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.4-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.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 be166a8c5b015ba240b3b8e14fce21d6e42d605c9a425cbb8609c37ff0640aa7
MD5 4dc37d4b71df78716867f4888ca48025
BLAKE2b-256 e584b78e0de5983ade4cc04e2fda75aa4a6e8e28614370227943f86c0abbb87b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.4-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9acb9d405595e7b138de1450437c293ae387c5171b5f0892e4e4898902cefbcb
MD5 9a28f12ea678ffc7de659413222b44c5
BLAKE2b-256 9d9ab9f4a1f1bd57bf97dea76477f4ee278a9e483d3cf94297704bf5c4356ede

See more details on using hashes here.

File details

Details for the file visagene-0.3.4-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.4-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 33647e396518ae5b66e1592951fc0ce2d59a004ca5bd09bb0dca923fa14714c6
MD5 70a007d948ea0bdef3c360452be717a8
BLAKE2b-256 8ba325e3148fe69ae8cb0f2488ab711fe04fe03923a31dfa52bfc2c8a778a17f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.4-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.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 89ce4ddb1cddcf55b6e4def620d51fb5ab7ecb22e59fbd9de756124cc4ec7e18
MD5 74c10b7d36250f88c3c57c6b4b35d70e
BLAKE2b-256 e127594f9ef4d2e3392b688a843d46744a5243e70c849cfbd793c7c9c381b8ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.4-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 62c05367d7b184246fa10a4ca2d65d49298bd420bdfae5c8b318d34bcd25f25c
MD5 74b53180e6d51621718532ff039cfd3d
BLAKE2b-256 f9d4f22b61bc7434efdb226a8a276675e37df5fc65f62e0120de529dae507555

See more details on using hashes here.

File details

Details for the file visagene-0.3.4-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.4-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2cc11eb867651205431246ace1ced6b3bedb702a415de7e418999be229c5b9d3
MD5 6d53678383d240f5e814cdf4e9e96215
BLAKE2b-256 f3dc46bed3b1a69fbb5d73289b0cfdd7e9e4840f1249c41545236efd378ce37b

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