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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

visagene-0.3.3-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.3-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.3-cp311-cp311-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

visagene-0.3.3-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.3-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.3.tar.gz.

File metadata

  • Download URL: visagene-0.3.3.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.3.tar.gz
Algorithm Hash digest
SHA256 789f84558ddcd8fd942fa12bd1bc0cc512624a48975fdac223b66acdcea3da5c
MD5 c8a4fc28d7392af21b81e1ac8b6b7a84
BLAKE2b-256 6f0cce0b1e147b3e75a74db2d46b4b6fd6cc2947527711dc8bd57f7941789ab5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.3-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.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 1138b865961069829a88dfea5071585fb1621fe195f8f65a2444be7ab45c6315
MD5 643b6efa39fa23e763fb33e41cf005bd
BLAKE2b-256 41fcdaaaaea9bb32da7cd8377245d85eeccadbad410b68c6d12e87831a28dafb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.3-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4f66aa0bcdf1955dcb96cc1fa204b342113e328c87aedcc5e5292c4b8284f497
MD5 469abda23a7fe71a5ed1783f1bb96070
BLAKE2b-256 20b3559d5f5b020acd810390b95da379d9d3f39be1ae0c0f7e495e1b8e18d13a

See more details on using hashes here.

File details

Details for the file visagene-0.3.3-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.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 51ca507f05538e304cbb3031067419fe701efa72e3d71d4539f038cf71a39ecf
MD5 5466f735f4c3365696e5cfa0105dc31b
BLAKE2b-256 efec5d603b8aeaca8a23926cc69c1889f457911ac7c9f0b9248d5e0eb242b75c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.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.3.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e323adb452a434874eaf63d6ba58c3e887dac7c0fa5d050ecbd52b8f332579b8
MD5 e6620f0ea58654c17ad3bd2e0be95c7c
BLAKE2b-256 a203e064b5eea13f7423eeb2da6b2da1f0fddf6c3735f7f74a07cdc1f814e2b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ac59767234058807f114215b54b5d18239cdcce3b6c73051ccb236eaaa016613
MD5 de3030d7ce59ec101ba2dc9b380f2af0
BLAKE2b-256 850363708233c8b69a5a15dcdda1e348ecc97b6b510834c6f4dc3b390b4fafe3

See more details on using hashes here.

File details

Details for the file visagene-0.3.3-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.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ce3d16d7224eac5537bbf76bcda424375d05a063ceda9fca2736acd2c26da56c
MD5 6739504e091de3788fa88010f2965b09
BLAKE2b-256 896396b36b72bf4b02fff50f51dfedeba3b62aaabab98587dda961cbe21118bc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.4 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.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0df41caa748c87894a35edc1ffca88b73377d3583eab0d7543c416edfe058cf1
MD5 be493074d4c214c2dd984954e827e7ed
BLAKE2b-256 8161914b16c997a2cf1ad7c2bddf3600d905f554720283164d8441201572f893

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.3-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9565de3f9406975c0a7bc5f0b1e50cc59571adec564030dc51651d9786bd002f
MD5 80f25c45b956f7376652c7cf12913cc2
BLAKE2b-256 1779301c8905c0dd1c753d032a148ca0cf28387791fc61122f81fd0251d2c9b7

See more details on using hashes here.

File details

Details for the file visagene-0.3.3-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.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ee6a40dee9104ce6fa8ba1afe32aa508b1bb11a9c4ea69c7e66a9014de101059
MD5 83305b7e5d3547d4ae9a608ffd3765ba
BLAKE2b-256 a0047e36aedb5cf8212da520bc3d43ee3ab2681299468507733c30badd4819fa

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.3-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.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7ead3d6a2a223b994efe0c6e87143a66ee45242a04ba2ce902f7f4b86f2741b4
MD5 c71e98d4fae6d7ba9ff19836e039fd70
BLAKE2b-256 933a0614b4e7176efa828e23d831b47973c2f81284b85d112ae58f34b2ef78b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.3-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 c92d6a354657b4b8dab5ca1ef48ddc1178ae776928a64b45aa19d8879c41c169
MD5 878d8156f6aaf97a039d8e7d60ba0c4e
BLAKE2b-256 1cf7d45984ae8f11b7ea5e36e0f556ac9a3238f26eb1a7b4cdaf324bff3f311b

See more details on using hashes here.

File details

Details for the file visagene-0.3.3-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.3-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 53d1a1d3bb5a141a5a9cef1fb352509a6fbe86653f96c79e687ad2e559d80b1e
MD5 460942bee0baff9e0cc90e54f9ecd5a5
BLAKE2b-256 8d128c74cf44b2f01916e36b66271edab6b674f549ac66cea15347eb2ad99b1f

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