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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

visagene-0.3.6-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.6-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.6.tar.gz.

File metadata

  • Download URL: visagene-0.3.6.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.6.tar.gz
Algorithm Hash digest
SHA256 88b4115e97b5c0263f9ec134294e5b8edd8fbbcec3b28a605f808998e5b4fbff
MD5 adaeba36c1fb07bfee160c0009665df9
BLAKE2b-256 3b9db5e70f21b425ce2684f38e5f6c630714fdd23912f8e94092c04c8d1bbb22

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.6-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.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 51faaef76aa33e0b3185d9dee4900c11a644fdd3b6279642bd64355325785cd7
MD5 c0e7cb9b2ad12d295a1dbfd013cb5505
BLAKE2b-256 0625b84f005b4867a26139e3aeadd62a15618a4ce79435d56e82f076ffef25ba

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.6-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 67bc0cea91776e88ff9fc0d52ae7e7ccd07fe88843e475f9811337720768a068
MD5 7b7676523c4fd30f8b09efc3316ff850
BLAKE2b-256 f87b0874fb4f4dc984908b9fa7139199b30f9b88863a87c113e04e7fd6acd39c

See more details on using hashes here.

File details

Details for the file visagene-0.3.6-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.6-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d3aa962c2bf9403b079511cf67b487eac2df1394f0eec336672f686ab5fd3e29
MD5 7cda9bf012c61a355828687ddce4857d
BLAKE2b-256 a89abf48d5a94a8ab3e07a7e95191c4488518974ccd08ddc5cca690a6ecadfaf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.6-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.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3b045080914123df921e6fbfecce71b1f311de357b55fb054dfa9fc0bc860cb3
MD5 662f102751438cd4a6253dc25c437a0b
BLAKE2b-256 99e14fd32f24d0a828b0bc74e78207d33fd76c33f89d522e3a69a0ecf0a8ad81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.6-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9988827e8f0e7265c3190fa1b08f557e1f7a4a31345b8570695b4f768f99e02e
MD5 b9366fd725612dc7610c64ca9edfd0cb
BLAKE2b-256 9f927fec5204c97152cb3f96d4e32be4e21b2146019eaab57ff3008ff1bccfe5

See more details on using hashes here.

File details

Details for the file visagene-0.3.6-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.6-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 add82fe358c62ee27f98a5c9cb95d1d14db784ff9f8e6eedef82fe8ab12d7322
MD5 cf398d0fd1e8c7850e82c2230a3a97c0
BLAKE2b-256 41c9a6f441163400aae5ae51eb0fc610103a437069e6d728e9f5cd1baf165e71

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.6-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.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 669ea4c1a384982331dc0986c079e8ee62b61e6543d024c718b1a6d0156fd577
MD5 0be1509c1fd7fed5e10ec95044562f6c
BLAKE2b-256 23339c5168b8694a109281f9c5a4f83df06f49401c50f4c5b922e0134bea78cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.6-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 39ffd5b8f0f22c7b676ef2893b9d3dbab645e98b62c055944cd107596b33e08f
MD5 2f793d8c8a86c4204907e3572aed594f
BLAKE2b-256 c3c344f0fdb037230a434b61162f25633033e351656b39c41af865a05b7530a4

See more details on using hashes here.

File details

Details for the file visagene-0.3.6-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.6-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 960d24ccbb2e1e01b068418ff857be6f2f80512b4a0515b408dcc9f33d4d51e5
MD5 687afd3529e1db053641b3c6333c1ce1
BLAKE2b-256 4bf8fbb9a7ff3a4085ef0489b9442e3af99f91cbbb683941ea369d856893e273

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.6-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.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3cecbc47612f4a8822888e345a3321844be256d5656ba22aff679c15327f1e18
MD5 663025070c0d19c6c1611ae560dc8b93
BLAKE2b-256 a233cba9c2a6818369ad01b307797f052c71ebf30766ff7b9f2f0f99fa7e3a6d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.6-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 524d6d82c3c8e73ca0ab59237ffd59a925a1cafb7f99c022c859b6baaaea1c93
MD5 4120c19f0b63bb16c276c33d8dbe8b21
BLAKE2b-256 5509d9fe9b875b2e881c81917f808deb9a396a0bc439d19f8653c3e68f18cace

See more details on using hashes here.

File details

Details for the file visagene-0.3.6-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.6-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2c136b51a06a562d8d77c2aaa9e1bcb10003f5533d2fb1a18fdf380d20ec3c22
MD5 000b08a207b9b5ffb0d8a4ea1d94f945
BLAKE2b-256 864ee38df9009aec22518a55fc2d197813632d80dff90c17bce18af64dd62878

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