Skip to content

rolandocortez/yolo-tensorrt-optimization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ YOLO-TensorRT-Toolkit: Optimized Inference Pipeline for YOLOv10/v11/v12 with ONNX & TensorRT

Reproducible optimization and benchmarking of YOLOv10, YOLOv11, and YOLOv12 models via ONNX export and TensorRT (.engine) conversion with GPU acceleration. This project serves as a technical reference, professional pipeline, and deployable real-time detection base.


Original model Optimized model

🎯 Objective

  • Export YOLOv10/v11/v12 models to ONNX
  • Convert ONNX models to TensorRT (FP16 mode)
  • Automatically validate conversions
  • Perform inference on images and webcam using .engine
  • Compare performance (.pt vs .onnx vs .engine)
  • Provide a clean, reproducible CLI for all stages

πŸ“Š Performance Graph

For exact latency/FPS values, see:
benchmarks/yolo10s.csv
benchmarks/yolo11s.csv
benchmarks/yolo12s.csv


πŸ› οΈ Base Image and Environment

πŸ“¦ Base Image

nvcr.io/nvidia/pytorch:24.03-py3

Includes:

  • CUDA 12.4
  • PyTorch 2.3.0
  • TensorRT 8.6.3
  • ONNX 1.15.0rc2
  • torch-tensorrt
  • Polygraphy, GraphSurgeon, Netron, etc.

πŸ”§ Benchmarking Hardware

The following hardware was used for all benchmarks:

  • GPU: NVIDIA GeForce RTX 4050 Laptop GPU (6GB VRAM)
  • CPU: 13th Gen Intel(R) Core(TM) i7-13700H
  • OS: Ubuntu 22.04 inside Docker

πŸ“‚ Project Structure

YOLO-TENSORRT-OPTIMIZATION/
β”œβ”€β”€ benchmarks/                  ← Benchmarking scripts/results
β”œβ”€β”€ data/
β”‚   β”œβ”€β”€ images/                   ← Test images
β”‚   β”œβ”€β”€ videos/                   ← Test videos
β”‚   β”œβ”€β”€ synthetic_data/           ← Test data for benchmark
β”‚   └── classes.txt             ← Labels (COCO - 80 classes)
β”œβ”€β”€ models/                     ← .pt, .onnx, .engine models
β”œβ”€β”€ outputs/                    ← Inference outputs
β”œβ”€β”€ notebooks/                  ← Optional analysis
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ cli.py                  ← Main CLI
β”‚   └── yolo_trt/
β”‚       β”œβ”€β”€ export_to_onnx.py   ← .pt β†’ .onnx
β”‚       β”œβ”€β”€ convert_to_trt.py   ← .onnx β†’ .engine
β”‚       β”œβ”€β”€ validate_onnx.py    ← ONNX verification
β”‚       β”œβ”€β”€ infer_trt.py        ← Inference with TensorRT
β”‚       β”œβ”€β”€ benchmark.py        ← Performance comparison
β”œβ”€β”€ run_pipeline.sh             ← End-to-end automation
β”œβ”€β”€ requirements-extra.txt      ← Additional dependencies
β”œβ”€β”€ Dockerfile                  ← Reproducible image
└── README.md                   ← This document

πŸ“¦ requirements-extra.txt

ultralytics
netron
onnx-simplifier
pycuda==2023.1
onnxruntime-gpu==1.20.2
opencv-fixer==0.2.5


### To use opencv-fixer:
python -c "from opencv_fixer import AutoFix; AutoFix()"

Installs packages not included by default in the NVIDIA image.


πŸ’» CLI Usage

Note: All the examples below can be replaced with any model from yolov10 to yolov12

🎯 Export .pt to .onnx

python src/cli.py export --model models/yolo11s.pt

With options:

python src/cli.py export --model models/yolo11s.pt --simplify --dynamic --validate

βœ… Validate .onnx

python src/cli.py validate --onnx models/yolo11s.onnx

βš™οΈ Convert to .engine

#FP16 (default)
python src/cli.py convert --onnx models/yolo11s.onnx
#FP32
python src/cli.py convert --onnx models/yolo11s.onnx --fp32

πŸ§ͺ Inference (Compatible for .pt and .engine models)

Image:

python src/cli.py infer --model models/yolo11s.pt --source data/images/example_1.jpg 

# Output:
outputs/inference_example_1_yolo11s_pt.jpg

Video:

python src/cli.py infer --model models/yolo11s_fp16.engine --source data/videos/sample.mp4
# Output:
outputs/inference_sample_yolo11s_engine.mp4

python src/cli.py infer --model models/yolo11s.pt --source data/video/sample.mp4
outputs/inference_sample_yolo11s_pt.mp4

Webcam:

python src/cli.py infer --model models/yolo11s_fp32.engine --source http://192.168.1.100:8080/video
# or to use your integrated webcam:
# python src/cli.py infer --model models/yolo11s_fp32.engine --source cam

πŸ“Š Benchmark (.pt, .onnx, .engine)

python src/yolo_trt/benchmark.py --model yolo12s --runs 100 --batch 1

πŸ“Š Plot Benchmark

python src/cli.py plot
# β†’ Plot by latency

python src/cli.py plot --metric fps
# β†’ Plot by FPS

Includes:

  • Export to ONNX
  • Validation
  • TensorRT conversion
  • Benchmark (100 iterations)

πŸ“œ License

MIT License.


πŸ“¨ Contact

Rolando Cortez GarcΓ­a
Email: rolscg@gmail.com
GitHub: rolandocortez
LinkedIn: rolando-cortez


πŸ“¬ Citation

If you use this project or the underlying models, please consider citing the original authors:

YOLOv10

YOLOv10: Real‑Time End‑to‑End Object Detection

@article{wang2024yolov10,
  title={YOLOv10: Real-Time End-to-End Object Detection},
  author={Wang, Ao and Chen, Hui and Liu, Lihao and Chen, Kai and Lin, Zijia and Han, Jungong and Ding, Guiguang},
  journal={arXiv preprint arXiv:2405.14458},
  year={2024}
}

YOLOv11

YOLOv11: An Overview of the Key Architectural Enhancements

@article{khanam2024yolov11,
  title={YOLOv11: An Overview of the Key Architectural Enhancements},
  author={Khanam, Rahima and Hussain, Muhammad},
  journal={arXiv preprint arXiv:2410.17725},
  year={2024}
}

YOLOv12

YOLOv12: Attention‑Centric Real‑Time Object Detectors

@article{tian2025yolov12,
  title={YOLOv12: Attention-Centric Real-Time Object Detectors},
  author={Tian, Yunjie and Ye, Qixiang and Doermann, David},
  journal={arXiv preprint arXiv:2502.12524},
  year={2025}
}

πŸ› οΈ Tools Used


If you use any YOLO version other than v10 (e.g., v8, v11, v12), please cite their respective papers accordingly.


About

Reproducible YOLOv10/v11/v12 optimization pipeline using ONNX and TensorRT. Includes export, conversion, validation, benchmarking, and real-time inference with FP16 acceleration. Built with Docker for full reproducibility and deployment-ready use.

Resources

License

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors