package for inferencing models developed at phosphene
Project description
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
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 (cpuorcuda) 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
Inferenceclass 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
timingsattribute.
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file model_inference-0.0.4.tar.gz.
File metadata
- Download URL: model_inference-0.0.4.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.11.9 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b444a36820e64416458a6cea404b19886ecfb698e9b989fd09f416244bde53c
|
|
| MD5 |
2297ffe065c573a10bfb04157312c793
|
|
| BLAKE2b-256 |
813a85213c18c26245033f879c4628629f57ba267b2fc3d82ed796e9b3723a37
|
File details
Details for the file model_inference-0.0.4-py3-none-any.whl.
File metadata
- Download URL: model_inference-0.0.4-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.5 CPython/3.11.9 Windows/10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
545a02f0124c34030682be0569ae58038e5639b999c2edac2ef0e89c63c43186
|
|
| MD5 |
c8fc43cce771d9121f0270e6c5c9580f
|
|
| BLAKE2b-256 |
c59abb41c602792f3f0f6b0e0c12107ef5dfa46b1091bc8ce7a925680f30dbd5
|