Skip to content
Projetos

Sobre

🚀 Kit de ferramentas para implantação de YOLO mais fácil e rápida para NVIDIA 🛠️

IA e aprendizado de máquina

Como estes números são medidos

Crescimento medido de estrelas

em 24 h
+1
em 7 dias
-1
em 15 dias
+1
em 1 mês
+4

Variações líquidas em períodos sobrepostos, não totais diários. Medições ausentes ficam em branco. Estrelas indicam interesse, não qualidade.

README.md

Original
TensorRT-YOLO

Easier and faster YOLO-series inference deployment for NVIDIA devices.

Integrates TensorRT plugins, CUDA kernels, and CUDA Graph, supports C++ / Python, and uses a single predict() call for preprocessing, inference, and post-processing.

Latest release GitHub stars C++17 Python 3.8+ NVIDIA TensorRT Linux and Windows x86_64 and ARM

Featured by HelloGitHub

Benchmark · Key advantages · Use cases · Architecture · Quick start · Ecosystem · Editions

English · 中文 · GPL-3.0


The complete workflow from ONNX export and TensorRT optimization to C++ and Python deployment

[!IMPORTANT]

This repository is Community Edition 6.4, licensed under GPL-3.0. The Community inference API is frozen and will not receive a new runtime architecture.

Professional Edition will be released separately, and its source is not included here. Purchasing is not open yet; see Community vs Professional Edition.

Benchmark

End-to-end latency and QPS comparison of the three TensorRT deployment paths

Animated comparison; static frame: assets/readme/benchmark-compare.en.png

End-to-end single-frame latency (preprocessing + inference + postprocessing) for the same YOLO11n Detect weights, FP16, batch 1, 640×640, measured on one machine with one process per scheme. Every number is generated by the scripts in benchmarks/ and traces to benchmarks/results/summary.json.

Scheme Version / commit Mean latency (ms) Mean QPS SD (ms) Latency improvement
Ultralytics 8.4.220 3.21 311.6 0.015 baseline
TensorRT-Alpha v2.0 f7e92a5 2.12 471.8 0.050 +34.0% (1.51x)
TensorRT-YOLO 6.4 8682096 1.69 592.8 0.004 +47.4% (1.90x)
  • Setup: NVIDIA GeForce RTX 2080 Ti, 22527 MiB, SM 7.5; driver 560.94; CUDA 12.6; TensorRT 10.3.0; Windows 10 19045; YOLO11n Detect, FP16, batch 1, 640×640.
  • Protocol: 100-frame warmup, then 5 rounds × 1000 frames per scheme, one fresh process per round; final value is the mean of the 5 round means, SD across round means.
  • Scope: end-to-end single-frame latency = preprocessing + inference + postprocessing; image decoding and result rendering excluded; TensorRT-YOLO runs its default CUDA Graph path.
  • Reproducible scripts, fixed inputs and raw results: benchmarks/. Results vary with hardware, driver and software versions.

Key advantages

The optimization target is the complete path from image input to result output, not just the engine.

  • GPU pre- and post-processing: CUDA kernels handle LetterBox, SwapRB, and normalization; Detect / Pose / Segment / OBB use dedicated TensorRT plugins.
  • CUDA Graph: reduces kernel-launch overhead for stable input shapes.
  • One core, two interfaces: the single-header C++ API and pybind11 Python bindings share the same C++ / CUDA implementation.
  • Concurrency and edge: use clone() for independent contexts over a shared engine (with additional GPU memory usage), with Jetson Zero Copy and built-in throughput, CPU / GPU latency profiling.

Use cases

Python applications, C++ services, video analytics, concurrent and edge inference
  • Python applications: feed NumPy / OpenCV images and receive supervision results directly.
  • C++ services: embed the single-header API with explicit resource lifecycles.
  • Video analytics: integrate VideoPipe for detection, tracking, and alerting pipelines.
  • Concurrent and edge inference: share an engine across threads, or deploy on Jetson and other ARM devices.

Architecture

TensorRT-YOLO architecture from inputs through CUDA preprocessing, TensorRT inference, post-processing, and outputs

The call path is: image input → CUDA preprocessing → TensorRT inference and plugin post-processing → C++ structs / supervision results.

Python and C++ share the same native core, keeping task behavior, preprocessing, and result structures consistent.

Quick start

Build the library, export a model, and run your first inference.

1. Build TensorRT-YOLO

Requirements: CUDA ≥ 11.0.1, TensorRT ≥ 8.6.1, a C++17 compiler, and CMake ≥ 3.18. This guide builds the Python bindings and requires Python ≥ 3.8; use BUILD_PYTHON=OFF for a C++-only build.

git clone https://github.com/laugh12321/TensorRT-YOLO.git
cd TensorRT-YOLO

pip install "pybind11[global]"
cmake -S . -B build ^
  -D TRT_PATH=/your/tensorrt/dir ^
  -D BUILD_PYTHON=ON ^
  -D CMAKE_INSTALL_PREFIX=/your/tensorrt-yolo/install/dir
cmake --build build --config Release --parallel --target install

On Linux, replace ^ with \. After building with BUILD_PYTHON=ON, build and install the Python wheel:

pip install --upgrade build
python -m build --wheel
pip install dist/trtyolo-*-py3-none-any.whl

Add the installation prefix to CMAKE_PREFIX_PATH, or add the Windows bin directory to PATH.

2. Export ONNX and build a TensorRT engine

Export ONNX with Ultralytics, then use trtyolo-export to adapt the outputs and integrate the required plugins:

yolo export model=yolo11n.pt format=onnx batch=1
trtyolo-export -i yolo11n.onnx -o yolo11n-trtyolo.onnx -s
trtexec --onnx=yolo11n-trtyolo.onnx --saveEngine=yolo11n.engine --fp16

Pose / Segment / OBB engines require custom_plugins; see the corresponding task examples for full commands.

3. Python inference
import cv2
from trtyolo import TRTYOLO

model = TRTYOLO("yolo11n.engine", task="detect", device=0)
image = cv2.imread("path/to/image.jpg")
result = model.predict(image)
print(result)

task must match the exported task. For profiling, initialize with profile=True and call model.profile().

C++ inference
#include <iostream>
#include <memory>
#include <opencv2/opencv.hpp>
#include "trtyolo.hpp"

int main() {
    trtyolo::InferOption option;
    option.enableSwapRB();
    auto detector = std::make_unique<trtyolo::DetectModel>(
        "yolo11n.engine", option);

    cv::Mat image = cv2::imread("path/to/image.jpg");
    trtyolo::Image input(image.data, image.cols, image.rows);
    trtyolo::DetectRes result = detector->predict(input);
    std::cout << result << '\n';
    return 0;
}

Use ClassifyModel, SegmentModel, PoseModel, and OBBModel for classification, segmentation, pose, and oriented object detection.

Models and ecosystem

Supports YOLOv3 through YOLO26, plus YOLO-World, YOLOE, YOLO-Master, and other variants. See the trtyolo-export model support list for the authoritative model and export matrix.

Integration Purpose
trtyolo-export ONNX output adaptation and plugin builds
Detect / Segment / Classify Detection, segmentation, and classification examples
Pose / OBB Pose and oriented object detection examples
Multithreading / multiprocessing Concurrent inference examples
VideoPipe Video analytics pipelines
nndeploy Inference workflow integration
Dockerfile Containerized deployment

Community vs Professional Edition

Community Edition 6.4 is free and open source, focused on stable synchronous inference. Professional Edition rewrites the execution path with configurable pipelines, multi-model Ensemble, and multiple sessions; its source is not public.

Community and Professional Edition throughput for Detect and Segment

Test setup: RTX 3080, YOLO11n FP16, batch=1, 640×640 C++ benchmark; warmup=100, iterations=1000, median of 3 wall-clock runs, CUDA Graph enabled.

Task Community (sync) Professional (sync) Professional (dual-frame) Gain
Detect 877.7 qps (1.139 ms) 1022.9 qps (0.978 ms) 1107.5 qps (0.903 ms) +26.2%
Segment 273.1 qps (3.661 ms) 321.5 qps (3.111 ms) 328.1 qps (3.048 ms) +20.1%
Capability Community 6.4 Professional
Execution Synchronous predict() submit / dequeue with configurable pipeline depth
Multi-model Ensemble Not supported Multiple models with shared preprocessing
Multiple sessions Create instances with clone() Open sessions directly on a loaded model
TensorRT ≥ 8.6.1 ≥ 10
Source and license Public source, GPL-3.0 Closed source, separately licensed

[!NOTE]

Gain compares synchronous Community inference with the Professional dual-frame pipeline and covers Detect / Segment only. Results vary with GPU, driver, TensorRT version, and input dimensions.

Professional purchasing is not open yet. See the Professional page for full details.

Explore projetos relacionados

Carregando…