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.1.1.tar.gz (1.6 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.1.1-cp313-cp313-win_amd64.whl (781.5 kB view details)

Uploaded CPython 3.13Windows x86-64

visagene-0.1.1-cp313-cp313-musllinux_1_2_x86_64.whl (835.3 kB view details)

Uploaded CPython 3.13musllinux: musl 1.2+ x86-64

visagene-0.1.1-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (835.1 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

visagene-0.1.1-cp312-cp312-win_amd64.whl (685.8 kB view details)

Uploaded CPython 3.12Windows x86-64

visagene-0.1.1-cp312-cp312-musllinux_1_2_x86_64.whl (837.6 kB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

visagene-0.1.1-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (837.7 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

visagene-0.1.1-cp311-cp311-win_amd64.whl (788.0 kB view details)

Uploaded CPython 3.11Windows x86-64

visagene-0.1.1-cp311-cp311-musllinux_1_2_x86_64.whl (837.1 kB view details)

Uploaded CPython 3.11musllinux: musl 1.2+ x86-64

visagene-0.1.1-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (837.4 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

visagene-0.1.1-cp310-cp310-win_amd64.whl (786.0 kB view details)

Uploaded CPython 3.10Windows x86-64

visagene-0.1.1-cp310-cp310-musllinux_1_2_x86_64.whl (836.2 kB view details)

Uploaded CPython 3.10musllinux: musl 1.2+ x86-64

visagene-0.1.1-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl (836.9 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64manylinux: glibc 2.5+ x86-64

File details

Details for the file visagene-0.1.1.tar.gz.

File metadata

  • Download URL: visagene-0.1.1.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for visagene-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c9fa7b573ec88ba1f3bd5cc85531d021c2916e04f2a021f6c458e3beae999b1d
MD5 3535714a3624dc53e10afca6f3b338d3
BLAKE2b-256 11954801f27a81abddf9bc4de37e7f9351054b093f5080f4e4f664ed67654410

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.1.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 781.5 kB
  • 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.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 8a4951d570cfaa4d32d0066e78f6548e20be6634694ec89410a38ad04fa34fce
MD5 f8fdf37b6ea3e8ca08db5b2756a4a262
BLAKE2b-256 bae36d30315ff140fbd843681a4aa884c405619b2f412f2e53b290019d77e0f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.1.1-cp313-cp313-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 eda0b58716688faa72a38ec54141f352e425423917215a0fef07b4e76b6babd9
MD5 60d67300dabfd4bf38fc0a5ac67a4eb5
BLAKE2b-256 e2e5cd75e8e79289d50fda341738a97e8d5709d9e264678a52d94e6b3c511c1e

See more details on using hashes here.

File details

Details for the file visagene-0.1.1-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for visagene-0.1.1-cp313-cp313-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 0a1e4e44ecfc17536c19f799d74ded935e014aeb977b7f6790bfd4609ed243da
MD5 19add0d6e4385df0e84847963aebb350
BLAKE2b-256 0c3f70a1281126185ddd937845a9ae0e45cd383bf0671676a36a4d798bbcfbdf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.1.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 685.8 kB
  • 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.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6f9c4dd1f007998cdbce8512033e80cfcd4ef8c8ec111938eed91f43c33a9724
MD5 396af7d9fadab8707d373c4aaf28ee5b
BLAKE2b-256 85586f3f6d49239bfdc9f9d894c259192c352cfbd215f6ae42d9dd12bf3f00c8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.1.1-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 e8c404789a99c925d7088dfe2cee943e73a3cc1580522dfc9f6b457359179b82
MD5 65dc655c3b7e8a8a956ff765bd597758
BLAKE2b-256 fcefe8cac27ae920f17e44270a942d250969f94a252e6c6c80c408a3d9ce54fc

See more details on using hashes here.

File details

Details for the file visagene-0.1.1-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for visagene-0.1.1-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 61e8c3e41cebf93642d0becbf75f1c0bc04854409e8bbf20828cf4b705c7f29d
MD5 514404e8e06bafb58bad065637dd6001
BLAKE2b-256 00d334b9e4d166946de05f88bbd614138d6fae93f7c7a83507e0b5cc52c7948d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.1.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 788.0 kB
  • 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.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 123bd4000e739c5b5fb385cd0a780add638d91623b9a6d95c6a935d8846c1b34
MD5 90a46c6f72df04143ffbab6cd08f7fee
BLAKE2b-256 d84eda5dbc80d459f891fd0834c1d170f915e072f248c7addff7b464a4a6f76b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.1.1-cp311-cp311-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 570e3208ad398b28c8a46dabffc1f855e88ce5a719e19ece2bfe49b8d2f5a11a
MD5 66a1145cc85f2ea5a93b09e37be7d723
BLAKE2b-256 15982c901f22eb1569724783b443dbfa6033b9e0abcf156dd27dd6e72b67d044

See more details on using hashes here.

File details

Details for the file visagene-0.1.1-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for visagene-0.1.1-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 57924f6f20056bebcb4d36d6dc4025de2d2aa564d204da4f9f7f96d20651ac4c
MD5 e31ae4a9ec30218a29292cf228c987a2
BLAKE2b-256 364bc76e6ad35a51dc0d3e6f15e1fd8b0cd96f1d61c5a86be374197a86427329

See more details on using hashes here.

File details

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

File metadata

  • Download URL: visagene-0.1.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 786.0 kB
  • 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.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 98193fdab48a064e3ad86df5a0042b397cc003cf5c5429ed685f9af6658dc871
MD5 83c38a41726cf1ce55731cdee0d57954
BLAKE2b-256 694e231749e57b60c7c78616067794bef5949973cc1f78d996b59c0541e1357a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for visagene-0.1.1-cp310-cp310-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 4ad32383a6672cd2828d0af323b040dbd17778e06c0985b84a0cfe077330cff0
MD5 3c37de41472b18b3a636312fe9363e2e
BLAKE2b-256 8e7f827f23264015457773c7360cbc5bd8ea40b1c1929fb007bd763cf46898f0

See more details on using hashes here.

File details

Details for the file visagene-0.1.1-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl.

File metadata

File hashes

Hashes for visagene-0.1.1-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
Algorithm Hash digest
SHA256 58b59df46464bf7358bf30f323dd5eb05511c8b462ee0c172cc76dc004b0e228
MD5 3f80a75aa497b8c4558878edaf32f400
BLAKE2b-256 f585ae46acae93da8c1142c1002d180efb1fe8d355f369151a36d009adefff3b

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