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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

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

File metadata

  • Download URL: visagene-0.3.1.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.1.tar.gz
Algorithm Hash digest
SHA256 82cd2a53365372b4f646b8fe0bcc0df14055f64eb099397b7f3336c995a7f344
MD5 ca9d8eab2ddf3fb4ba021758d56c5328
BLAKE2b-256 cb180e68ea15360b0e214815b9e3e9f51f97747eb1973bf057db80ce1bac7329

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.1-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.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 36f39d401374793d6f78613d8bc43675c0959a76dfa6a42f3582f88a96caaecd
MD5 3d34fd090c2a2e46a63cf6a5fea5139f
BLAKE2b-256 e12fd6aea33279e61f2c3b7889a0117a4fecf73c52955e3a69e06f6ac2271833

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d5b3336eb2a26678b2e10c22cdcf902fdb5eb8113119f981ed027b4585f0f0e5
MD5 fcbeedfebb3973e00defee50990053d6
BLAKE2b-256 38982a09726c518e44f5e98d9be7391eb4b4156e5b4be371b3786cb6e5d8e24c

See more details on using hashes here.

File details

Details for the file visagene-0.3.1-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.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 722aa8ff845e6a3f25db96a91aec4d905b42048ff095e5a848c3105f61e12431
MD5 b1400a4188f671dd14c7c86324fef429
BLAKE2b-256 2bf12acbf7187fda9d9914dccec9abad7730d42050860666784d1ba4f009fdb6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.1-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.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 acc8329cc55cf2628188f4550437741b9574fc2a1387ca0723976e317ac3c1b4
MD5 ded0ec2826be4d0ef051298992f8ba2f
BLAKE2b-256 0aaa34d6fd3720dc3400eb2fbbdd693f105638cc189074d9827d9a8109a83664

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 debf80b57c43b8a03fec5b00b8f5a00e72861bdde483789e125633827cd3cbff
MD5 08d922e696fc226b7de52a9823ffefaa
BLAKE2b-256 72ec1e1ce967f44f4f694aa69031063780b5b3a404be18c4f1147f494603d1b0

See more details on using hashes here.

File details

Details for the file visagene-0.3.1-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.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a60b24f58c29ab83a5c039e4a2d52fc513a6808a7ee062d142b81715253822bb
MD5 4b3bcf64a675ae394de3faced4de0a6a
BLAKE2b-256 d8ac0125e5aae8b35704a2a367709526ea0551aa789f5656212c14939626e01e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.1-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.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 72597e0a359bead212e382d0555d762237dd673d396c1bd7fa41b1c355b82bff
MD5 f75ad9a62e469dd4ebb3eb595f95d77d
BLAKE2b-256 02af97d8a8fc715740bdb15e5a93295b0dededf8aa0daf43f02dc3acf8bfcdb3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5daadbc8b390af302c9f9a42d361ed66a7b375e595feed333f5008b3324b59d3
MD5 05fe5cbd9d6662bd17315218339c8afc
BLAKE2b-256 f39eb38026dcaa4456c6ac69a4c4a5e446b273e698cb60433663e4aca4ad29ff

See more details on using hashes here.

File details

Details for the file visagene-0.3.1-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.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 fe6561999b5395c3e48cd94784d5af3a933063b067138cc9de9d438895b71869
MD5 b75ae116723a71b1026502b6c9b58706
BLAKE2b-256 475a9a4ec3cb8e7befa6442d81f7d4dcb3b081046574500928179894e8ed765a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.1-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.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 58ef02cfe6db1bb5eae36c48747ff42f37d77b8c7cfae7368886fe1e8c972b95
MD5 844d716e09b4d09ce4ddfac732bd1b39
BLAKE2b-256 4474aac3f5aa9b54cabd1b100422175b027dfed44b9b94690aac7daf209ecb3c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4582b89cf1b56dad936c1ea8b282556d4ae3528eaec38d97afaffc6c9490b8d1
MD5 318c62f3644dd68410ba98dc997230de
BLAKE2b-256 34670a051429ade4d8e1d9eca5c9fb033e9bde3e3a9ec230ad1c05c88e5ca611

See more details on using hashes here.

File details

Details for the file visagene-0.3.1-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.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c26ac5efbbeda0da37096bd90954caabb4860767ad6ce880760a2f0b419602a4
MD5 3002b5b3b2d827e8f10d0e2390556425
BLAKE2b-256 271eee324e4e036e7d40f816ba010650d80874fb4174601d9e81a4031596282a

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