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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

visagene-0.3.0-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.0-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.0-cp310-cp310-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.10Windows x86-64

visagene-0.3.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: visagene-0.3.0.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.0.tar.gz
Algorithm Hash digest
SHA256 f89fc82214e68928d6b5b9ed00b640d3667a409063f7e2eb380091c0f2916151
MD5 a815522003dcc0dbbd1cb737c9a98898
BLAKE2b-256 6ed42d6ebae9b554d0ecaf5e85ed3d88468f2115b7cc0d7b73ae17bf9cf9603a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.0-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.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 394a073580ff87ffc7b311c9e573773598684cd30391471bda3bb826964254a1
MD5 c8b6a91fe99e16ede5ba4840cbb117b9
BLAKE2b-256 b6bbdbe67b44630032f389b33cbd0374e61961088cd66228dd3d443000f79d0b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.0-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 570526025275c570650002d432ac429295125cbf0d14a0ded41a35cdddda29c2
MD5 be81df4efe67d01b9a2b93759bf7f749
BLAKE2b-256 ae9497a0d3288d5d76214bb1868717466f4fec47692c2a1c37c88489a7446ee3

See more details on using hashes here.

File details

Details for the file visagene-0.3.0-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.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 056694cf22c4de677c803195451032041dd4d2d8529b4b3320d125ac2c2d1ad2
MD5 0053ba8990b8d70b42dadf8e21417b3a
BLAKE2b-256 aab484a7fecebaad18e8a00fead324d5e64583601d9444a305d1518d0b58a502

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.0-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.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3b2bffb308cb633af4f09e66734fa6047650ac58a642739dc4f4d1223133c863
MD5 a37590cefd11743b87810ca9458f71c7
BLAKE2b-256 755c83201120694dd6a7e572bde58cba629402669e8ec4f0e44ce96d182dc913

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d14f09a1cc576584d60dfb87f30a61b264ba2fab9f8ba4ddaa767f79da9a4d4f
MD5 bcb35263900ee299f8362275b34ea65d
BLAKE2b-256 3a175f5fe370f07253c128258438a07494d7d609f38902cac711dfb2ea99f1c9

See more details on using hashes here.

File details

Details for the file visagene-0.3.0-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.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ff292ab0456be50a1f69f51d4213e55fe0b1107077e36462c6a54db22184beb5
MD5 9c650e0203182ec035bfc018f0b2cd2b
BLAKE2b-256 0b6c32b47d4564deebfe02a6ddc6e7f8879d202e28c0edb73386843f18bc718d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.0-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.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a259864f4905a4cd53616b154cadcc735dddcc65ebfe7655274a84a0c19b0ffe
MD5 6f2a5245be10aeadd78e5c284a038b4e
BLAKE2b-256 c2c60f46968f4c64242425cc1e088d40925a1e9b1b672a335451052919a24952

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.0-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 39d69bbca00e3bb6462f513ceb4ec040a5f99c7aade4081fe451bf49c44ac1b6
MD5 07abe35f2dcc1daf094eab7bcd359d39
BLAKE2b-256 8370798a5d2e96300d06b3e4dcb1f2ff13517ad8e9a1cfef15a41b01ba0f735e

See more details on using hashes here.

File details

Details for the file visagene-0.3.0-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.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ad64c55e2f30d94a1617a4647d8f4554d21ece69cededb7cdd80023bc41b6111
MD5 42e3c5e431b6fd795c7c1b99d08bf072
BLAKE2b-256 316e6dbedc4b5301f8bbc10ea537c425f7518fec57c85ce80d0a1be7d2973e9a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.0-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.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0ad9a5836dee783574ffcf4690f117c523e14278988d04b01dce80e6d22692af
MD5 c1e206a602901c82ec9d682409ecf837
BLAKE2b-256 e7c9d7bac60c29870953316c554ef261990d12c73a60447383e93398a0010bf7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.0-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b18b965b1c0c1596d1d07cbe18239bfd289cef6cae6a8c70612c572abf6f6d62
MD5 dba87fdf4bdabdf9ecc5b0e9ce02f15d
BLAKE2b-256 09ec78956256ea2065316beefba86310fe49021ebfdf736bd60965d323f7d84d

See more details on using hashes here.

File details

Details for the file visagene-0.3.0-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.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0443ed95df4cc0c9c5ca99251171efbfba2676f6237bd862673cc8bfe9e312f5
MD5 71eadb6d79c1374d0e76eb99185c7b85
BLAKE2b-256 21bdfc0d42a7391f81bf3212c47be2435dfda1cbf3070bbe0a4c1eac3a03f171

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