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

Uploaded CPython 3.13Windows x86-64

visagene-0.3.11-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.11-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.11-cp312-cp312-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

visagene-0.3.11-cp311-cp311-musllinux_1_2_x86_64.whl (1.8 MB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

visagene-0.3.11-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.8 MB view details)

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

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

Uploaded CPython 3.10Windows x86-64

visagene-0.3.11-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.11-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (1.8 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.11.tar.gz.

File metadata

  • Download URL: visagene-0.3.11.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.11.tar.gz
Algorithm Hash digest
SHA256 ac52dc3f94b25b1893a7b9ae69b78055211309ddbfbc9ba27aeb452a5f00aca1
MD5 71dd6ca68fa7578a1388251beea3bac9
BLAKE2b-256 ff4f425a2f181320266e90257d96b52bcded65122347505e4deb422a944a1fc9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.11-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.3.11-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 4ef27ecb80a3981f9ba22019280bc7c67a47b1ad28d933a27df1dfedfe1ae879
MD5 13957d6499dd2b563304fb3950eba478
BLAKE2b-256 7088cfc2e27e29801dd9f424426708d322e05519dd3593d042259b0080e79a87

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.11-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c29ece31904eebb80b8ab9eed9863a9a7a055ae8a1d5ca120fe0454f42d088a3
MD5 47b67e26819c41f21d78b865c6d5817a
BLAKE2b-256 0c5bf8fef79e9e359b4597c058fa8e7717d02621798f34dfc17bedacd88f3d03

See more details on using hashes here.

File details

Details for the file visagene-0.3.11-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.11-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 57dd177acf092342a6900ed3508a1aff8b8a3d6e4f3a84d0617decf5e66ec194
MD5 18e3cf405bc5c4d5c20ec67a39b8fb95
BLAKE2b-256 8de01f433fd087b71eca117b72cf17d8d9ed55c607cb37618f383359c8d77172

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.11-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 1.5 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.11-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b8d191daaa98739bfe651fc5c466956b3342219b995bef28ff9aee7c8b17fee5
MD5 080cdb01febb584c53a4e95f9883ec9e
BLAKE2b-256 4391ce68e223b486e6137f87fcb599c6d331cf0415351ef3f2c8dd53d3e2016b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.11-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ab0d1550fe18d650561b1635606b91505f4f8139c459d89e9da827a74394383f
MD5 1833707ff054af0d3cfa9d22de125ff9
BLAKE2b-256 18a5ffab87766085af81e08c0f056523b7d50c2b9654ba164a914af30c164bb0

See more details on using hashes here.

File details

Details for the file visagene-0.3.11-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.11-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d6856c7855f35c94dbdc9710eefb6d783b0dd303c5aadc62e231c235a74d03fa
MD5 dc4ee08baf7559ddc0f44d16b084201a
BLAKE2b-256 6fd9b1236ae0d31d26f374bc57c79094548be5d82158af3e28f5130e899788b3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.11-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.11-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 da06d5fabc644505cef805bcb0ab84904fb32e254bbf26ef710d410e78fe99c3
MD5 12b626d9308b757c9f1cd86e98c698ee
BLAKE2b-256 4978811a0aeef4e3644a1be2ab7af29f994bf92e3bd31ad8192e420da9d39e00

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.11-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 428c2f165d6aeb62b9d7e315c9fabb84a52b18e34c72fe255f1ca71f72a098d9
MD5 b4259dab9a59decb45a1fe50751ee386
BLAKE2b-256 794fed0d12a0bdd251a93223dfc7571423a843674faa17d648b5f79e37619619

See more details on using hashes here.

File details

Details for the file visagene-0.3.11-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.11-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 91ab9b70e6f84b4644bea2f306679af5f6f357b55fe3c2bc7365a14a94a491a5
MD5 8cd69e715f23bf2e3b209b9e4d0ed675
BLAKE2b-256 996aa89a522da17e7c9f1223a6ee6280f3717d23e061756fbb901c8281e15136

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.11-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.3.11-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 13376c79786a125eae1cf5423072379dd4cc2e988d51db4e19e5acdb18df8b6b
MD5 27444cbc66d581ba48258618cecd7c6d
BLAKE2b-256 e5d4018d5fbe419acb5e8c67b20eaba4c4d0ce13582d8fcfe27c2300533994bf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.11-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 29bdf01932e8177d4570ffbc19a0721d7ce104d26d1658e49bd14927b9d29af7
MD5 9fb91eef4c7b4ffe1c2ab092b47fed73
BLAKE2b-256 a96a5ddef35028a4a38488bc0930c6e16cf80bfde41e6f5457324c912d56e8d3

See more details on using hashes here.

File details

Details for the file visagene-0.3.11-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.11-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4f6ea86d771f8b81f9f0267655a84726c01c32f5b681f9512e35a1f5928559fe
MD5 323295e3b119c89c05624d2b355ae6c8
BLAKE2b-256 6954837dd0b3870e7c44ffc8a6aedadcd2fe93e90326713329189a4f359163bb

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