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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

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

File metadata

  • Download URL: visagene-0.3.7.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.7.tar.gz
Algorithm Hash digest
SHA256 388921c6980e3892d0db5ae86c3b6171a08366e64fe61ec5059499662461908b
MD5 658fa93dc2c2a00b38a59be43773e00e
BLAKE2b-256 dc3039f5050bd454768f9bff2f3c3e70bcee26644853f0bb134ec987d9992a6d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.7-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.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c0025dcaa95e2ca9f9cef4c94f2574a6c6395222b63ebbafe82bfd0ff92ae038
MD5 d592d186dec40ff6e6ba7aa172904ff4
BLAKE2b-256 89a8c63dbc53d9037f2e892480d01801dec29a7b67db69dd0ac294584b31ced6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.7-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 78ad34e7acf8dd26fece3696c4e8e076bbc6b3902fbb6ca710a4de34bc51f9a1
MD5 eb12508314c749f699a706c3576c6e4c
BLAKE2b-256 9b9f3977ec1145344088c252805283f19f73ad2d75523510e300dfb29f1d1314

See more details on using hashes here.

File details

Details for the file visagene-0.3.7-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.7-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 546a0b9146ed13c143d529e16b789807d54de4666f864405a44f0154cb32d4b7
MD5 5f778e6b33c6628d3685c463a20a906c
BLAKE2b-256 5de5fa60ad2131a1655ed1906301abaac9a27199b508ebe77d1f5c1f613c01e2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.7-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.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 b733059e24d998a04b755b912d324d1c11542eb42d2e7069f960c8cdba8ea9bb
MD5 1d8dd9e0127f85f0357785e48a3de5c4
BLAKE2b-256 a50dfe44d8b29e73aade9d49b1a88c856753f130a3bda9a5fde485aabb7ce3e7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.7-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 596d63ccb0f61b70d13338ce08b7ada7a94541d94dcc0b5bf187ddfa99fffdbc
MD5 8aed272859c0d791b6a0e00f6a0c896d
BLAKE2b-256 7bd84872c8312155d9f6a0ce7e740f0866698ad499fdaadd7d39c0f93ccb586e

See more details on using hashes here.

File details

Details for the file visagene-0.3.7-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.7-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a1504334445b75daecd7dbe720f688974a83699684765f0ca476b5572ad7535d
MD5 5a387a9049c226485561cfbc7c69f3fb
BLAKE2b-256 ec9d14b24afc2fd163387282f75d38b49ce6fde2427b34cf35f82df2ca2bbbc5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.7-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.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 bb4fb9097b9b895ef62efcea7e7cbe20892238097d926f583ed6f0561345047d
MD5 5ce487754a5a77c3868a16246bf55a47
BLAKE2b-256 28347532725c3ecb37a18ba1855ac83f53965f891c3fb57e9b91f60acf0b5e4c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.7-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 3dea6bb3350976497b2eb81d66a36f919ab2a8623d81a6ea8985ba2b367b2424
MD5 663c617d4ec6f9eab468bec526e9926f
BLAKE2b-256 b841b5e6423ef0c2c9ad57b92383e71fe0cd2fbd7039dc95bdc75e7fc3c883a9

See more details on using hashes here.

File details

Details for the file visagene-0.3.7-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.7-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 572f012f68c6f81e2c9cf867b1a802d14556d2c97b21a35e6e808e0e20d8c7d9
MD5 1f31ac5e82d6eda5cc5afd2c5a1e993f
BLAKE2b-256 3166ac68a5b0dd1ed4218e2ccc6be0b0dc9b3dbfb2fd8abacffa6f9cf1369f00

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.7-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.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8b6f1623e659dcf37c39dde661add8c056fd39bcf827a0edff268ab00adecbfe
MD5 1b19bf73da6b613a084f52f473322c05
BLAKE2b-256 20d603dab7345d37bc7daa9007c3dace9025cb2eb7b77f631961bc26d0b8e3e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.7-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5d420b71395d08a2cfd15460b3006d6ec42d8ff9c9938075f33a6f3bcdc800b2
MD5 278e52f429e8bfccf3a8f0c83c983c29
BLAKE2b-256 6b6d29ced14f47f14a9a3048836f4b2121b83b2ffc9923f4eeb91d5941bdc824

See more details on using hashes here.

File details

Details for the file visagene-0.3.7-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.7-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 828a4e5a77c3bf615645a7aaf266f2b1221a312d05c89b3822fb19c62a6e9085
MD5 5a3388be1c4bbff7a775aab2cceb35d2
BLAKE2b-256 f9e6fbe712a5e5aa54f8154d9a2d475ded728a2de93bd3821146bb5ca0836c5d

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