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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

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

File metadata

  • Download URL: visagene-0.3.2.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.2.tar.gz
Algorithm Hash digest
SHA256 768f411513ce97fbb00371cd68674bbb6751d19c69611a44b09a0e09b0668461
MD5 c5dd6c0b50817b2734e3cab881ac7123
BLAKE2b-256 5fd7fb7dbfb17f5902647a58e5fdbca9e0f81cd82f803bb5ff8faab31041ca88

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.2-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.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 05311e1808e29145b3efcb97ded45384e43a8470236c76c18896a5ea4f794f89
MD5 68b8adc0c316daae37aeddbe240e18f4
BLAKE2b-256 4e799f8a9e91ff33f49d4c33b47315bf8801bc7283b12e3cb011484a377c23c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.2-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 126bab9ccd0cc582417b320afc515783e1e23620130a523d3cbaf27c0e0bbce8
MD5 f5cf4f2a201dfedb97e908b822d7db02
BLAKE2b-256 5a749dbe61814b4d7ba5dea0f15dbc3b1d28eb8d0328a733c1fd42cd97e14ff9

See more details on using hashes here.

File details

Details for the file visagene-0.3.2-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.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 99d381e2c7a60182b41c40d413619ba918326898cd3b617e5b84c684d311a638
MD5 0cc2dbd2b0cdc53cc8e370223d3c292a
BLAKE2b-256 92115e583df82779626c226ba74e17f4552d0b2f638cc7c3a4ea6cd6dfdee813

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.2-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.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f7c128b57022ad45259d89e817bb412071c78a5907c3cec6b36fd7e4206ffed0
MD5 8c51380e13f4ef24fc2acb7295ef180b
BLAKE2b-256 9cef081e409e8ca74bee3a0c3610175f61a5bb1b261b7a8b695463640a94606e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.2-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 fd1e9e0079749a5a55d9ab21af773255b074ed5acee9f6f57b397486433304d7
MD5 7cad297f8f62c94420eef3e4343689d9
BLAKE2b-256 94291d4182e559d44ed03d398b170e5d33d535e63e65e82e8a448cdcb7dfb04c

See more details on using hashes here.

File details

Details for the file visagene-0.3.2-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.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 edc79469da6f15ceb52bbdd74912f09d17fd537dcf8077d24082cde1da1bd3a2
MD5 39b063584f66e1120e49f285fd9fd344
BLAKE2b-256 8802eb382632eddfb53653cb149770eca01c6631b3669b77fdd46667e91d363f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.2-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.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 de5043c32f9388d0a75dcf2c5a0ce786abc89cd553b3ce6f42a3f0841aa969fe
MD5 b59e22fa9776ae7ff0e96d6b24b5620f
BLAKE2b-256 1ee7843cbaf4611cdfa317773b75f67876c7991491c799bc446ba753bb975ae5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.2-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ece8771dec401f319a1e1322b55a7374b329bc138b5b25be6474399f43640d95
MD5 aea3798e4942d2f91caa62b3932363e1
BLAKE2b-256 6e1d96132b042918403b34cba82e4efb42ebb4b6e3d2b2901b24cabfba1aec0b

See more details on using hashes here.

File details

Details for the file visagene-0.3.2-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.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9553519a3e260c0855a24b39e8a9d7c336da1f29b792ca715ba9875f9c75fcb8
MD5 8e519d55504e3838cc15eb157906d7ce
BLAKE2b-256 3b782cdc868e9f7ba3250943a1317d74008ee57367edca22dcda4971121aa1e6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.3.2-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.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c6d0a9a0874392f91cf9d4e0718016fd09f2284453a09ff5c4ff60ef537a6c2f
MD5 14810c88a54ae401d867af3efab151cc
BLAKE2b-256 18729936baf9f315b541fef3bc91edf04ad61125285f10653bd1e989a047a250

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.3.2-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2830bb99a2657ef60810642e25904c84da33adad94fb1b15919d80362d5c50e0
MD5 54a372dc1e5992471a615e55f3d55fbc
BLAKE2b-256 d954d5f25b4bc9cc0379bfc626877ad9e87b1847f680d46336ddcd528908e3f9

See more details on using hashes here.

File details

Details for the file visagene-0.3.2-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.2-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0cd434dc910c54f092b1bf1449c954acac51a65cd149e6cda82236db8bfab4da
MD5 98bb283d71056305436629a1ee461fff
BLAKE2b-256 a7ea07f95065476b62fde6a904202ba2fde22f660e73b410d23b9d3d89fcc324

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