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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

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

File metadata

  • Download URL: visagene-0.3.9.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.9.tar.gz
Algorithm Hash digest
SHA256 079cda0fbca1921c751f0d9fea883538fa96d01d82bc5620e64612dd8413fcbe
MD5 470289aede7891df48f74bc44b3267b3
BLAKE2b-256 4adcfef7431510adf8d49ba70c9198a55d18637c47d3ff829f1f92213e8ae6bf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.9-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.9-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ac4b9dd04c9834aa2f401095bd79177131376a28656703bf974a2519b48f26e0
MD5 a40643565e6247aeae787cc68f38e91d
BLAKE2b-256 853db07bc70d7c75626ae51a4a1e211eb7e91d4ab8b4556177fcca0a9010dca0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.9-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8b4481723838c3a060311e3ed068218e9bc0b3dd5d14b1e7ff07263246037e7d
MD5 c483d427433bd1c2454f4005e139af88
BLAKE2b-256 3ce7d3828859f296cce4526f66fca8d467118ea6f6da4d9bf62a97bf3413fe77

See more details on using hashes here.

File details

Details for the file visagene-0.3.9-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.9-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 61e64ca1c36ae439a54ba821b246af0e330f971fc29b7efdbff18807546067dd
MD5 b9577e6d2f89bd1fa4ea00822a599f21
BLAKE2b-256 0f0ec3ae52d2137bba52c57993173512eaf142bcdb55437295a469e35ffdb68d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.9-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.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 9ee44d9beb6936f040ad4d6ed90db798db8b31bc055795d317e5b22e5bbddb93
MD5 b7560cd9dd342685f6264bb4f1b310b5
BLAKE2b-256 8fcfd5fcb79ed76d92002da6638b51d183042dbc48427085e2c29eca3b95f205

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.9-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 919b4af67147796c91fbb5510046dd00fec4ab2ae8cc3165d289dbb4c28c7459
MD5 887592e20ceffd45839b2e090c8f7490
BLAKE2b-256 3b2ae439a7d06402b812f875572e068d9954a0d406a7e98f7056f0af15fe3237

See more details on using hashes here.

File details

Details for the file visagene-0.3.9-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.9-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5da4b474b55c2c2129feb0a414c9e3dd98350ebfcfc703531ff81cb719ab4663
MD5 3000ff5a2e4b409c48bafbefd42b1de7
BLAKE2b-256 fe4ee5231e4e93a718b82fb23691e5047bc92f2801040ea52856cd78608012a9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.9-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.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 29c440bb904548d8c4147983f50412ccad465f1782c17a22108ef879ef7d6c95
MD5 440ccb86147027db77edd682ed9b1b1e
BLAKE2b-256 c200028ad52e1f8f373445f2d8cdecb41c3fe18f6ae1dc3563a3011c5c4d8a4a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.9-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 96da1cc69c0cd77326a9c0693470fa1ddbd722d1c01c470db0558f751a2e340a
MD5 cb0c29b9dcbe37632271b4560c172826
BLAKE2b-256 eac331b8f54091243dceb145870b314f112776c55cc02afc65c1a6af17706405

See more details on using hashes here.

File details

Details for the file visagene-0.3.9-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.9-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b88d993ad7dcbacc5bb5c73f26c59b6ae4c8be3033edb5ccdbbd1a04edb6d119
MD5 35dbe1b35799de1fffe01791669df998
BLAKE2b-256 12240dfa1e46dfb4d30c6993736be44d58abd0f9d0f955a03576fae4617aa97a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.9-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.9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 56a56d852eac9fa3766e841ddf1ac3c7717a750d1215e5ccd45e3af7f8dcd342
MD5 308acc9cde578834126c474e1aff16c0
BLAKE2b-256 e8851ae1dd03316fc1f444402075c4e245ca2a4675ae3644b084ec2f7dc090d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.9-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 5df7f3469f3a921d740c67fe8a561a1ed4afe298de36ac227bd0b7aea639651f
MD5 25cfff762661afebb93d6e594d80fcdb
BLAKE2b-256 7776910c3cc1202f2ebc7a93849f058930421545c71cfb90125c7ff86f70527c

See more details on using hashes here.

File details

Details for the file visagene-0.3.9-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.9-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 183bf5714651873dcccdb08ac5cc3199e69ae89e66f5ab0f02cd94b0f051c535
MD5 3ff9281b29dcda5a99d870a7783baaa1
BLAKE2b-256 3738520ee9e55bd8099dc2771f306ecfd9e91321070aa84227a27483d0933f30

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