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

Uploaded CPython 3.13Windows x86-64

visagene-0.2.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.2.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.2.3-cp312-cp312-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.12Windows x86-64

visagene-0.2.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.2.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.2.3-cp311-cp311-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.11Windows x86-64

visagene-0.2.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.2.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.2.3-cp310-cp310-win_amd64.whl (1.4 MB view details)

Uploaded CPython 3.10Windows x86-64

visagene-0.2.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.2.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.2.3.tar.gz.

File metadata

  • Download URL: visagene-0.2.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.2.3.tar.gz
Algorithm Hash digest
SHA256 9d0c75d853999711019b4d5f6f53ec31747379f4c61a459882743bdd552411f0
MD5 c39d403891e79dfbdebccf35f3871045
BLAKE2b-256 9595ffb5bc4f36242ec57bb66a6da49ea32ab64ba8e6f1b035e61cdd8126fbd3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.2.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.2.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 9e875291236eaa36644c0ddf7968b8e4a08a141988964108dc3b82a1c44d6e21
MD5 a330be7aaf7411c94437f6a14de042c7
BLAKE2b-256 1cf76de221061ccc202acc5823e9ce0c8ed7dea31fc21a8f51b78b096ee11756

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.2.3-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0cfc52ec2633b124d1de2871c465c6bbded03d06bff99e5d0ff8dc427d4a31b8
MD5 cf9efd111ed4f1472fedae624b0fa72e
BLAKE2b-256 2bc49d06d83a0af4f60433e3185055c97cbd07f37d92771168bc1c54172116bd

See more details on using hashes here.

File details

Details for the file visagene-0.2.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.2.3-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 307bf125d555142a816d4cc03a32a56838811aa39b1f8dd821ce67d1331d7cee
MD5 60587e6b1c984c462c859932c4389353
BLAKE2b-256 2f64b297be6e9938d98fe15a58d60e6930187b4329b03053e752cf17d3330592

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.2.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.2.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c2f4414567ae450ae73406e9fc29060c8037b3115adf60a860840588bd193a7e
MD5 91a6f14f6964e68a1b1b370a7beb8b97
BLAKE2b-256 d0d4fd54af733670f12facd0c4ba010aaa271d9c75c4da9777ffc1940481c956

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.2.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fd344f451dd8fa6aebab917b9e1e0dee995f2d7c673725fecdbedfc2dde5fe8d
MD5 65dc5b082d7bbf39c34c310a43a6344b
BLAKE2b-256 4bf0568e8bc262c74139ec1c909dd4ec95b96f877ef40c897598891fd58a23bd

See more details on using hashes here.

File details

Details for the file visagene-0.2.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.2.3-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 37495aabbf2da2f3e854aa9f4f8d57b677a53b94ee47b71e373b0068a062c818
MD5 1dceef6244cdf7a0e59f8de9f41b90e2
BLAKE2b-256 d99ff48af3d7c9e00b541bc8f9388143354f7a24724fd93f136a57a4ae04924c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.2.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.2.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 90faa77d17915262a0917abb3aa65722c103d04248c6a52b140f3977d2a67db8
MD5 9cdddd5d5a3e6f79f118e63847d8df28
BLAKE2b-256 34816b7424f7385c9e831c871dd1f9cd3b99525f992c952cd01cc3b7e58fced9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.2.3-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 51debe4b90db8fd8f8c201be4c35f5d0c5f1d8419029fe26d3ff8795b862c6e5
MD5 e64cc8f710ea29517f5525d004f26825
BLAKE2b-256 eaf46e04019e8f9c7d0af11edbdb5506f0f40b2b4550c5e45cef2272beb1f1de

See more details on using hashes here.

File details

Details for the file visagene-0.2.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.2.3-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0ee30a45e69d2ee461c2c617e5c7d1f5c129bd9b6ea9a64430ca45724d311a2b
MD5 fb3e17fa22c02b803a4ed66384a94492
BLAKE2b-256 1ce7fa941d42eb7eda24229643ed5b5b29c40806b298749d2c7de6aba0a26122

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.2.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.2.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 967d7836d1dd7c18d4c7a10e91bfbb1568e1e77c7167076129e1b95bd405e31e
MD5 26c27e98a3750d81823fdf4051063773
BLAKE2b-256 74c069d8baa8e77bfe214df8f25f7474153923c8bf347726013cf350d9fcd124

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.2.3-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d4338913bbdd6f9e13e6f719e45e79a7088a611e3d9d30308729220e34984ca8
MD5 aa2265bf66532b977a9ed3d64177857b
BLAKE2b-256 39f9f262a5bdb32b341abd0fcfb767c6181cf9a9da2c22f0c8207cb761f0acd2

See more details on using hashes here.

File details

Details for the file visagene-0.2.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.2.3-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2e89ee13f51b1cdc1c4c9b223a4585156339690cbb8f5df79a0afb9eff065298
MD5 7373f97425ff9a28bcd61c3e22759618
BLAKE2b-256 e0d6f3bb002f57d479a5bbf8615490d34af7e7f7a621b62b139f706ba7a3e770

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