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

Uploaded CPython 3.13Windows x86-64

visagene-0.1.3-cp313-cp313-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

visagene-0.1.3-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.6 MB view details)

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

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

Uploaded CPython 3.12Windows x86-64

visagene-0.1.3-cp312-cp312-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

visagene-0.1.3-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.6 MB view details)

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

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

Uploaded CPython 3.11Windows x86-64

visagene-0.1.3-cp311-cp311-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

visagene-0.1.3-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.6 MB view details)

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

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

Uploaded CPython 3.10Windows x86-64

visagene-0.1.3-cp310-cp310-musllinux_1_2_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

visagene-0.1.3-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (1.6 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.1.3.tar.gz.

File metadata

  • Download URL: visagene-0.1.3.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.1.3.tar.gz
Algorithm Hash digest
SHA256 aae872dcb3db726bfe876caba55a78b4d0746d7c579514ca2befb07ef683cec6
MD5 88d59c22956cd20a12a7b6d3585eb35b
BLAKE2b-256 02edbbb85b823a7161c5a2dd6fdebe208c47a36fc3a7e94c27133eb4fa62f241

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.1.3-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.1.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6141b69cfad29190a4fbd297610dda448799cf711b57a9f44a13cb68c2fb392a
MD5 fe3729af79aca5784a1b17e669285b04
BLAKE2b-256 4f685894dd023f5351737adb1ea65ea45a6a7e88686180c5616bdbaa473c9e24

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.1.3-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a15a20515391e5baaff41b90344b189821bb6cf9f956bb2cf5d8018e817c3cda
MD5 e51e0bfcc239b5168a7f034eec483a05
BLAKE2b-256 029cd08451f8badbfa708337c11e859ffa050ce30481766506784518b328e500

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.1.3-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 0800b0da225c55554db7bfe8cf85b6a75ef7112344e20141a3fe7932a5cf7449
MD5 affee1a9eb40c267abf4344faa8e2613
BLAKE2b-256 a3640db8208f7da6acc2d0ce7f6a879e03526211f7175c1d8f9befb13993c9a1

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.1.3-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.1.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 910a79cace05a3ceba9c29419dc5876b3b6e5cd3d97881ff4c99a55931468e6a
MD5 c78f8f14f557809d25dcd12b5cca7b00
BLAKE2b-256 321899aa6b5ba39e5cb44788cf0e3fe22fbda20d815235091fbc9facefa623c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.1.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 de96b60cdf6fdd8470668d072648f079bb1980d66e1a1dbf6fe403761026a156
MD5 375ae2741f21a3afef872e2ec5d0eb61
BLAKE2b-256 3f29ffc62d470632322dd69fb99469b090a6c6c577eefd376569e52f3a0433f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.1.3-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 06c5416d198221a8bfe93c6e79e6307ef900b6146ecda12b3a9aa8c5cc42326a
MD5 3b03bb9779f700b3c6a651a33082b619
BLAKE2b-256 58618c97eb6150934b65ffcaa4a5f43cdad6f3c9d34a037ee2a069739b9609b6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.1.3-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.1.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c59a3751dacd3dbd35be651723a3eb6382a77db40b7e57c4f792482850db6382
MD5 19f8ea049e935bc192020081f301c338
BLAKE2b-256 eeb8c3f0d94663ebe6e4dbf6e7becc47808ad92aa5ed17e80e1817b3e196ddc8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.1.3-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c4013b4732dc12ac3900c48c5ff4715dc2215bbc6361e64acdef2c5d59f65c89
MD5 32b50369a6d59769eafada5e82a32d3d
BLAKE2b-256 dbee5c802d4eaed43883c73cbe8a3eb79efbae33d24c6a3df2b2c30760fa7c88

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.1.3-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 068b4c14f8f85cf6face7792178b6a75be9e9df0c838dc7218a8eaaa37a4623f
MD5 362ad53d0bbfdb2a46e329bb732a1a5b
BLAKE2b-256 18738ebb36f736ba9e4505e62f5b1ffd2461a3335850a3aa4ed82b59a0cf9762

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.1.3-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.1.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 eb2dc561c048d9c9b5622dd71efe1240a3232e9d683b6fb954bf4f1291bb9fda
MD5 e959e3cfac176e070bea27b2cd9f0c63
BLAKE2b-256 7afeaed28571ba7e3da376aa866f6f49b88fc1cc8c5b5295ef6c3797b3e37717

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.1.3-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5e4e7b96e125bb6f249264403c5b773fa388af5d02b3dbc4a08011bb9b85fda0
MD5 cfe2c2974864d44b9c70c3b2924fe142
BLAKE2b-256 2ca0bf6f4912f197b0582073fe20f56f5fecefe1984ecf77fa3b599db2bc43b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.1.3-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 4848ec18a13f30480d832be47b7e40a594cbc88e78e7b4f13e71be9fd117bc5d
MD5 b3d3cd0c9eb57b8d6f3ecfc4fb272024
BLAKE2b-256 0fafe7c47f423f368c1f45439cdab6e80a27eed546219c4f64a6c79c86342c01

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