Skip to main content

A lightweight and modular Python package for handling computer vision inference (image/video) with Triton Inference Server.

Project description

⚡ TRISM Inference Client

Perform batch inference on models deployed in a Triton Inference Server using a Python client.


Introduction

TritonModel supports: - Connecting to Triton Server (gRPC or HTTP)

  • Multi-input and multi-output models
  • Automatic batching and data stacking
  • Auto-generating config.pbtxt based on model metadata from Triton

Input Data Structure

The input passed to the run() function is a dict:

data = {
    "input_name_1": [array1, array2, ...],
    "input_name_2": [array1, array2, ...],
}
  • Key: must match the input name defined on the Triton Server.
  • Value: a list of tensors with the same shape (already padded but not stacked). The client will automatically stack, split into batches, and send to the server.

Example Usage

from trism_cv import TritonModel
import numpy as np

# Initialize client & run inference
model = TritonModel(model="model_name", version=1, url="# Triton server address", grpc=True)

# --- Case 1: Batched input ---
# data is a list of images with the same shape (HxWx3)
batched_data = [np.random.rand(640,640,3).astype(np.uint8)] * 3
outputs_batched = model.run({"INPUT": batched_data}, auto_config=True, batch_size=2) #batch_size default=2, can be customized
print("Batched output:", outputs_batched)


# --- Case 2: No batch ---
single_data = [np.random.rand(640, 640, 3).astype(np.float32)]  
outputs_single = model.run({"INPUT": single_data}, auto_config=True, batch_size=1) 
print("Single output:", outputs_single)

Output Format

The TritonModel.run() method can return 4 different formats depending on the model:

Output Type Format Notes
Single-output list[np.ndarray] Each element = output of one input sample
Length = number of input samples.
Multi-output dict[str, list[np.ndarray]] Each key = output name
Each value = list of per-sample outputs
Length = number of input samples.

Example of how to handle the output:

# Single-output
for i, sample in enumerate(outputs):
    print(f"Sample {i} shape:", sample.shape)

# Multi-output
for name, samples in outputs.items():
    for i, sample in enumerate(samples):
        print(f"{name} - sample {i}: shape={sample.shape}")

Auto Configuration (config.pbtxt)

TritonModel can automatically generate the config.pbtxt file by reading metadata from the Triton Server. This helps users:

  • Avoid writing input/output configuration manually
  • Ensure compatibility with the server's model definition

Environment Requirements

  • Python >= 3.9
  • opencv-python
  • numpy
  • tqdm
  • tritonclient
  • trism_cv (custom module)

Quick installation:

pip install opencv-python numpy tqdm tritonclient[grpc]

Notes

  • All inputs must have the same shape for batching.
  • Input keys must match those defined on Triton.
  • The model must be in READY state on the server.
  • Multiple batches can be processed in parallel to increase throughput.

License

GNU AGPL v3.0.
Copyright © 2025 Tien Nguyen Van. All rights reserved.

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

trism_cv-0.1.0.tar.gz (22.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

trism_cv-0.1.0-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file trism_cv-0.1.0.tar.gz.

File metadata

  • Download URL: trism_cv-0.1.0.tar.gz
  • Upload date:
  • Size: 22.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for trism_cv-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9d20083c1ff3666e435a65fc10d6a8d87209b444c030beae4228215b9e933414
MD5 a997b2088b7a55cc3422184c205e34f4
BLAKE2b-256 dfa6287b880856f6cd79fd1a3c0b85833d18826d0a03d72bd527dbac83ee2022

See more details on using hashes here.

File details

Details for the file trism_cv-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: trism_cv-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for trism_cv-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 96fb73e21655bfc4ebe325b1f67012df10cd910309b0fc11d4c6d921e2a3fbce
MD5 5e460c037c3adbbbb7fc952748c18d8e
BLAKE2b-256 f1f1254b47d4436765331c8e40d8796022f08c47a22aee26b228e2bac18bc8e3

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