Skip to content

Repository files navigation

trtutils

PyPI CodeFactor

Ty Ruff PyPI Build

A high-level Python interface for TensorRT inference, providing a simple and unified way to run arbitrary TensorRT engines. This library abstracts away the complexity of CUDA memory management, binding management, and engine execution, making it easy to perform inference with any TensorRT engine.

Features

  • Simple, high-level interface for TensorRT inference
  • Automatic CUDA memory management, CUDA graphs, and pagelocked/unified memory
  • Support for arbitrary TensorRT engines, on CUDA 11, 12, and 13 with the corresponding TensorRT versions
  • Engine building from ONNX, including strongly typed, DLA, and quantized builds
  • Ready-to-use image models: detection, classification, depth estimation, and hand-object interaction
  • CPU, CUDA, and TensorRT preprocessing with built-in postprocessing
  • Model download and ONNX export for many popular architectures
  • Benchmarking, profiling, and NVTX instrumentation (with Jetson energy/power metrics)
  • Comprehensive type hints and documentation

Installation

trtutils does not pull in CUDA or TensorRT by itself, install the extra matching your CUDA version:

# CUDA 13 / Jetpack 7
pip install "trtutils[cu13]"

# CUDA 12 / Jetpack 6
pip install "trtutils[cu12]"

# CUDA 11 / Jetpack 5
pip install "trtutils[cu11]"

On Jetson devices, TensorRT is provided by Jetpack, so use the matching jp5, jp6, or jp7 extra instead, which installs cuda-python only.

Additional extras:

# ONNX graph utilities used by the builder
pip install "trtutils[onnx]"

# Quantization CLI/API tools
pip install "trtutils[quantize]"

# SAHI (sliced inference) integration
pip install "trtutils[sahi]"

# Numba JIT acceleration for CPU operations
pip install "trtutils[jit]"

# Development
pip install "trtutils[dev]"

Quick Start

Basic Engine Usage

The TRTEngine class provides a simple interface for running any TensorRT engine:

from trtutils import TRTEngine

# Load your TensorRT engine
engine = TRTEngine("path_to_engine")

# Get input specifications
print(engine.input_shapes)  # Expected input shapes
print(engine.input_dtypes)  # Expected input data types

# Run inference
inputs = read_your_data()
outputs = engine.execute(inputs)

End-to-End Image Models

Detector, Classifier, DepthEstimator, and HandInteractionDetector bundle preprocessing and postprocessing around an engine:

import cv2

from trtutils.image import Detector

detector = Detector("yolov8n.engine", warmup=True, preprocessor="cuda")

image = cv2.imread("image.jpg")
bboxes = detector.end2end([image])[0]

Command Line

# download a model and export to ONNX
python3 -m trtutils download --model yolov8n --output yolov8n.onnx

# build an engine
python3 -m trtutils build --onnx yolov8n.onnx --output yolov8n.engine --fp16

# benchmark it
python3 -m trtutils benchmark --engine yolov8n.engine --iterations 1000

See the CLI reference for all commands (benchmark, build, build_yolo, build_dla, quantize, detect, classify, inspect, profile, download, trtexec, and more).

Supported Models

The models listed in the documentation are officially supported for inference, including the YOLO family (v3, v5, v7 through v13, v26, YOLOX), DETR-based detectors (RT-DETR v1/v2/v3, D-FINE, DEIM, DEIMv2, RF-DETR), torchvision classifiers, DepthAnything V1/V2/V3, and HOI-DETR/Hands23.

Documentation

For detailed documentation, including advanced usage, examples, and API reference, visit our documentation site.

Examples

Check out our examples directory for more detailed usage examples, including:

  • Basic engine usage
  • End-to-end image models (detection, classification, depth estimation)
  • Engine building and quantization
  • Benchmarking and profiling utilities

Performance

Device YOLOv8m YOLOv8n
OrinAGX-64GB OrinAGX-64GB YOLOv8m OrinAGX-64GB YOLOv8n
OrinAGX-32GB OrinAGX-32GB YOLOv8m OrinAGX-32GB YOLOv8n
OrinNX-16GB OrinNX-16GB YOLOv8m OrinNX-16GB YOLOv8n
OrinNano-8GB OrinNano-8GB YOLOv8m OrinNano-8GB YOLOv8n
XavierNX-8GB XavierNX-8GB YOLOv8m XavierNX-8GB YOLOv8n
3090 3090 YOLOv8m 3090 YOLOv8n
3080Ti 3080Ti YOLOv8m 3080Ti YOLOv8n
TitanRTX TitanRTX YOLOv8m TitanRTX YOLOv8n

License

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

About

Quickly and easily use TensorRT inside of Python with support for models out-of-the-box

Topics

Resources

Stars

22 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages