Skip to main content

Torch CUDA install

If the identity_clustering package is installing the CPU version, you can install the right CUDA versions by manually installing it or running the following command:

python -m model_inference.torch_install

Sphinx Documentation

To view Sphinx documentation, clone this repository and run the following commands

cd pkg-faceswap-inference

#install sphinx and a theme.
pip install sphinx
pip install sphinx-rtd-theme

# generate docs
sphinx-build -b html docs/ build/

open the build folder there you will find index.html , open it with a browser


Inference Class Documentation

The Inference class provides functionalities for inferencing video files with models. It includes utilities for timing and tracking nested function calls to aid in performance analysis.

Table of Contents


Class Attributes

  • device (str): Specifies the device (cpu or cuda) used for computation.
  • shape (tuple): Dimensions for resizing clustered faces, default is (224, 224).
  • classes (list): The categories the model can predict, such as ["Real", "Fake"].
  • timings (dict): Stores timing data for functions with nested call relationships.
  • _clusters (None or dict): Stores clusters of faces post-clustering.

Methods

__init__(self, device: str, shape=(224, 224))

  • Initializes the Inference class with specified device and shape attributes.

generate_video_data(self, video_path: str, print_timings=True)

  • Processes a video to detect, crop, and cluster faces, and converts them to RGB format.

get_data(self, video_path: str, print_timings=True)

  • Retrieves essential data for frames, bounding boxes, images, FPS, and clustered identities from a video.

get_predictions(self, model, images: torch.Tensor, device='cuda')

  • Runs predictions on clustered face images using a model and returns logits and labels.

__cvt_to_rgb(self, faces: tuple) -> torch.Tensor

  • Converts images from BGR to RGB format.

__plot_images_grid(self, tensor: torch.Tensor, images_per_row=4)

  • Plots a grid of images from a 4D tensor.

__print_result(self, result: dict, image_data: List[torch.Tensor])

  • Displays results, including images, based on the model’s predictions.

__print_timings(self, timings: dict)

  • Outputs timing information for functions with nested call relationships.

__create_sequence_dict(self, identity_data)

  • Organizes identity information into a sequence dictionary.

__draw_bounding_boxes(self, video_path: str, sequence_dict, result_video_path: str)

  • Draws bounding boxes on faces in the video and saves the processed output.

Decorator timeit(func)

  • Times functions and records their nested relationships in the timings attribute.

Usage

Here's a simple example of using the Inference class:

from inference import Inference
import torch
from models.models_list import ModelList

# Initialize Inference class
device = "cuda" if torch.cuda.is_available() else "cpu"
inference = Inference(device=device)

# Load your model from ModelList
model = ModelList().load_model("face_detection_model", device)

# Process video
video_path = "/path/to/video.mp4"
output_data, num_clusters = inference.generate_video_data(video_path)

# Get predictions for each cluster
for cluster_images in output_data:
    predictions = inference.get_predictions(model, cluster_images, device)
    inference.__print_result(predictions, cluster_images)

License

This project is licensed under the MIT License. See the LICENSE file for details.


Metadata

Release files for model-inference 0.0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for model-inference 0.0.7.1
File Size Uploaded
model_inference-0.0.7.1.tar.gz 10.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for model-inference 0.0.7.1
File Interpreter ABI Platform
model_inference-0.0.7.1-py3-none-any.whl Python 3 none any Details

Total release size: 22.4 kB

Release files / model_inference-0.0.7.1.tar.gz

Download URL model_inference-0.0.7.1.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d1cfeb32aa7fc9c881a3ffe9679bca0c410afd72ee9629d73afee3d604fb53d6
BLAKE2b-256 checksum
How to use checksums
46a2b96cba0beea737233833b35d2daf93db693a356a581c434c710a8d0c5d1d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.12.9 Linux/6.8.0-1021-azure

Release files / model_inference-0.0.7.1-py3-none-any.whl

Download URL model_inference-0.0.7.1-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d4b24e02e4013dc85bbc210378ffce8ac1057b1bc68f9dfb01bb140a2836143f
BLAKE2b-256 checksum
How to use checksums
7fe302dcc56a6e9e12e3eb8bafd7670b1b29e1520007dc00bed9e41eb759f460
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.0.1 CPython/3.12.9 Linux/6.8.0-1021-azure

Release history Release notifications | RSS feed

This release

0.0.7.1 This release

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page