Ultralytics YOLO27: Join the waitlist.
License YOLO
Integrations

ONNX vs TensorRT for computer vision inference: benchmarks and how to choose

ONNX Runtime vs TensorRT for computer vision inference: measured Ultralytics YOLO26 speed and accuracy on 19 NVIDIA GPUs, and how to choose.

Miles DeansMiles Deans11 min read

Listen to this article

AI-generated logistics scene with illustrative detections; the inset shows Ultralytics Platform benchmark latency for YOLO26n on an NVIDIA L4.

ONNX and TensorRT aren't really rivals. ONNX is a model format, and TensorRT is NVIDIA's inference engine, which usually takes an ONNX file as its input. The real choice is how you run that file: with ONNX Runtime, which works across hardware and can even hand work to TensorRT, or compiled into a standalone TensorRT engine, which only runs on NVIDIA GPUs. In Ultralytics Platform benchmarks of Ultralytics YOLO26 on 19 NVIDIA GPUs, TensorRT FP16 was faster than the published ONNX FP16 results on every GPU and model size, with accuracy within 0.001 mAP50-95. Median speedups ranged from 1.85x to 2.55x across model sizes. The benchmark doesn't say which ONNX Runtime execution provider produced the ONNX results, so they don't settle how ONNX Runtime compares in general, or with its TensorRT execution provider. For Ultralytics YOLO26 on NVIDIA GPUs, start with TensorRT FP16 when latency matters, and use ONNX Runtime when one model file has to run on more than one kind of hardware. Ultralytics YOLO exports to both with a single argument.

Where to start with Ultralytics YOLO:

DeploymentStart withUltralytics YOLO export
NVIDIA GPU, latency mattersTensorRT FP16format="engine", quantize=16
CPU, non-NVIDIA hardware or mixed fleetsONNX Runtimeformat="onnx"
ONNX Runtime's API on an NVIDIA GPUONNX Runtime with the TensorRT execution providerformat="onnx"

ONNX vs TensorRT: format, runtime and engine#

Three different things hide behind the comparison:

  • ONNX (Open Neural Network Exchange) is a file format that stores a trained model's graph and weights in a framework-neutral way. You export from PyTorch to ONNX so other tools can read the model.
  • ONNX Runtime runs ONNX models. It hands work to hardware back ends called execution providers, such as CPU, CUDA and TensorRT, so the same file can run on a laptop CPU or a cloud GPU.
  • TensorRT reads a model, typically an ONNX file, through its ONNX parser. It fuses layers, picks the fastest kernel for each operation on the GPU it's built on, and writes an optimized engine.

So the question is really ONNX Runtime vs TensorRT. ONNX Runtime can also call TensorRT through its TensorRT execution provider, which lets you keep ONNX Runtime's API while TensorRT runs the subgraphs it supports. ONNX Runtime recommends registering the CUDA execution provider after it, so any nodes TensorRT doesn't support can run on CUDA instead.

Diagram of how an Ultralytics YOLO model is exported to ONNX and then run by ONNX Runtime or compiled by TensorRT

One ONNX file, two paths: ONNX Runtime runs it on supported hardware, while TensorRT compiles it into an engine for one NVIDIA GPU type. Ultralytics YOLO exports to both.

Benchmarks: YOLO26 on ONNX Runtime vs TensorRT#

The numbers below come from the Ultralytics Platform inference benchmarks. Each Ultralytics YOLO26 detection model was exported to the format shown, then its inference latency was timed on Ultralytics Platform GPUs at batch 1 and 640 pixels on COCO val2017, with warm-up excluded and per-run times sigma-clipped. Accuracy is mAP50-95 on COCO val2017, measured once per format and precision. The comparison uses the 19 NVIDIA GPUs (Ampere, Ada and Hopper) that have results for all four formats.

The benchmark page doesn't identify which ONNX Runtime execution provider produced the ONNX results, and it doesn't label any results as using ONNX Runtime's TensorRT execution provider, which hands supported parts of the model to TensorRT. These ONNX results describe the benchmarked configuration; performance can vary with the ONNX Runtime execution provider. If you want ONNX Runtime's API with TensorRT underneath, benchmark that combination on your own hardware.

Ultralytics benchmarks showing YOLO26n TensorRT FP16 latency by NVIDIA GPU

The Inference tab lets you switch model size, format and precision, then sort every GPU by latency, accuracy or cost.

Bar chart of the median TensorRT FP16 speedup over ONNX FP16 for each YOLO26 model size

TensorRT FP16 was faster than the published ONNX FP16 results on every GPU at every model size; the page doesn't specify which ONNX Runtime execution provider produced them. Bars show the median speedup across 19 GPUs; whiskers show the lowest and highest speedup on any one GPU. Calculated from the Ultralytics Platform inference benchmarks.

ModelmAP50-95: ONNX FP16mAP50-95: TensorRT FP16mAP50-95: TensorRT INT8TensorRT FP16 speedup over ONNX FP16 (median, range)TensorRT INT8 speedup over TensorRT FP16 (median, range)
YOLO26n0.3970.3970.3572.55x (1.79–3.28x)0.90x (0.79–1.07x)
YOLO26s0.4710.4710.4362.19x (1.83–2.93x)1.04x (0.89–1.19x)
YOLO26m0.5190.5190.4701.85x (1.52–2.54x)1.20x (0.90–1.38x)
YOLO26l0.5360.5350.5012.03x (1.67–2.73x)1.08x (0.92–1.33x)
YOLO26x0.5630.5640.4881.88x (1.67–2.11x)1.19x (0.92–1.67x)

Calculated from the Ultralytics Platform inference benchmarks. Speedup is ONNX FP16 latency ÷ TensorRT FP16 latency, or TensorRT FP16 latency ÷ TensorRT INT8 latency, on the same GPU, so values above 1x mean TensorRT FP16 (or INT8) was faster. Medians use the 19 NVIDIA GPUs with all four formats, and ranges are the minimum and maximum ratios across those GPUs. Accuracy is the reported mAP50-95 for each format and precision. ONNX FP16 means the published ONNX Runtime results, whose execution provider isn't specified.

Latency on four common GPUs, in milliseconds per image, as published on the benchmarks page:

GPUModelPyTorch FP16ONNX FP16TensorRT FP16TensorRT INT8
L4YOLO26n4.982.041.031.09
L4YOLO26x7.769.805.733.43
RTX 4090YOLO26n6.672.560.841.00
RTX 4090YOLO26x10.945.202.682.25
A100 SXMYOLO26n8.723.981.651.79
A100 SXMYOLO26x15.027.253.863.91
H100 SXMYOLO26n6.363.091.171.48
H100 SXMYOLO26x10.265.532.662.62

Three things stand out:

  1. TensorRT FP16 beat the published ONNX FP16 results on every GPU and every model size, with accuracy within 0.001 mAP50-95. If you deploy on these NVIDIA GPUs and need low latency, TensorRT FP16 is the place to start.
  2. INT8 isn't an automatic win. On YOLO26n it was slower than TensorRT FP16 on 17 of the 19 GPUs, and it cost 0.04 mAP50-95. On larger models it helped more often, up to 1.67x on YOLO26x on an L4, but it cost 0.034 to 0.076 mAP50-95.
  3. There are no ONNX results for the seven Blackwell GPUs. The benchmark page puts this down to ONNX Runtime having no Blackwell kernels in its test environment. TensorRT ran on all seven.

These results cover the setup on the benchmarks page, batch 1 at 640 pixels, so benchmark your own model on your deployment device, with your own data, before choosing.

FP16 vs INT8 with TensorRT#

Lower precision is the other big lever, and the benchmark shows why it needs testing:

  • FP16 (half precision) halves the size of weights and activations compared with FP32. In the Ultralytics Platform benchmarks, TensorRT FP16 matched the accuracy of ONNX FP16 and PyTorch FP16 to within 0.003 mAP50-95.
  • INT8 stores weights and activations as 8-bit integers, a form of model quantization. It needs calibration: a representative set of images is run through the model to measure activation ranges. The Ultralytics Platform benchmark used NVIDIA ModelOpt with COCO128 as calibration data.

As the benchmark methodology notes, INT8 pays off most on larger, compute-bound models. On the smallest models, the extra quantization work can match or even slow down FP16. Calibrate on images from your own domain, then validate accuracy on your own data before you deploy an INT8 engine.

Two bar charts comparing TensorRT INT8 with FP16 for each YOLO26 model size: speedup on the left, mAP50-95 lost on the right

At the median, INT8 was slower than FP16 on YOLO26n and up to about 1.2x faster on larger models across the 19 GPUs, while costing 0.034 to 0.076 mAP50-95 at every size. Calculated from the Ultralytics Platform inference benchmarks.

Engine portability and dynamic input sizes#

By default, a TensorRT engine is tied to the GPU it's built on and the TensorRT version that built it, so an engine built on an RTX 4090 isn't meant to be copied to an H100 or a Jetson. TensorRT has hardware and version compatibility options that relax this, but the safe default is to build on, or for, the device you'll deploy to, and to rebuild after a TensorRT upgrade. On Ultralytics Platform, the Export tab asks you to pick a GPU type for TensorRT exports for this reason. An ONNX file has no such tie: the same file runs wherever ONNX Runtime and a suitable execution provider are available.

Both formats support variable input sizes. For TensorRT, dynamic shapes need an optimization profile that sets the minimum, optimal and maximum input dimensions, and inputs at run time must fit within it. When exporting Ultralytics YOLO models, dynamic=True enables dynamic input shapes for ONNX and TensorRT. Fixed shapes give TensorRT more room to optimize, as NVIDIA's dynamic shapes guide explains, so use dynamic shapes when your inputs really vary and benchmark both.

When to choose ONNX Runtime and when to choose TensorRT#

  • NVIDIA GPU in the cloud or on premises, latency matters: TensorRT, starting with FP16. Try INT8 on larger models after calibrating and validating it.
  • NVIDIA Jetson at the edge: TensorRT. See the NVIDIA Jetson guide.
  • CPU, non-NVIDIA hardware, or mixed fleets: ONNX with ONNX Runtime, using the execution provider each machine supports.
  • You don't know the deployment hardware yet: export to ONNX first. You can build a TensorRT engine from the same model later.
  • Intel CPUs, GPUs or NPUs: consider OpenVINO, Intel's inference toolkit.

For the full list of formats and how they compare, see the model deployment options guide. Precision isn't the only lever either: model size and input resolution matter too, and our guide to pruning and quantization covers two more ways to shrink a model.

Exporting Ultralytics YOLO to ONNX and TensorRT#

Ultralytics YOLO exports to both formats with one format argument, and you can run prediction or validation directly on the exported model:

from ultralytics import YOLO

model = YOLO("yolo26n.pt")

model.export(format="onnx", quantize=16)  # ONNX FP16, for ONNX Runtime
model.export(format="engine", quantize=16)  # TensorRT FP16 engine, built on this GPU
# For INT8 instead, calibrate with a dataset YAML (coco8.yaml is a small demo set; use your own):
# model.export(format="engine", quantize=8, data="coco8.yaml")

trt_model = YOLO("yolo26n.engine")
results = trt_model("https://ultralytics.com/images/bus.jpg")

quantize=16 selects FP16 and quantize=8 selects INT8. Both engine exports write yolo26n.engine, so run one or the other. For INT8, point data at your own dataset YAML so calibration uses images like the ones you'll deploy on. See the export arguments and the ONNX and TensorRT integration guides for every option, or follow our step-by-step posts on exporting to ONNX and optimizing with TensorRT. You can also export trained models in your browser on Ultralytics Platform.

Frequently asked questions

  • ONNX is a model format, not an engine, so the fair comparison is ONNX Runtime vs TensorRT. In Ultralytics Platform benchmarks of Ultralytics YOLO26 on 19 NVIDIA GPUs, TensorRT FP16 was faster than the published ONNX FP16 results on ONNX Runtime on every GPU, with calculated median speedups of 1.85x to 2.55x across model sizes and mAP50-95 differences of at most 0.001. The benchmark doesn't say which ONNX Runtime execution provider produced the ONNX results, and none are labeled as using its TensorRT execution provider, so test that combination yourself if you need ONNX Runtime's API.

  • Yes. ONNX is TensorRT's usual input: its ONNX parser reads the model and builds an engine from it. ONNX Runtime can also call TensorRT through its TensorRT execution provider.

  • No. In the Ultralytics Platform benchmarks, TensorRT INT8 was slower than TensorRT FP16 for YOLO26n on 17 of 19 GPUs. It was faster more often on larger models, with a median of about 1.2x on YOLO26m and YOLO26x across the 19 GPUs that ran every format. Each time it cost 0.034 to 0.076 mAP50-95, so validate an INT8 model on your own data first.

  • Don't count on it. By default, a TensorRT engine is tied to the GPU and TensorRT version it was built with, so build it on, or for, the device you'll deploy to. Keep the ONNX file as your portable copy and rebuild the engine for each target.

  • TensorRT is the usual choice: NVIDIA JetPack includes TensorRT, and building the engine on the Jetson itself tunes it for that device. The benchmarks above don't include Jetson, so measure on your module before you decide. The NVIDIA Jetson guide walks through setup and export for Ultralytics YOLO.

Written by

Miles Deans
Miles Deans

SEO Lead · Ultralytics

Miles Deans is the SEO Lead at Ultralytics, based in London, where he drives the company's search strategy and organic growth. He previously held roles at Adobe, Kaizen, and Virgin Media O2.

Comments

Ask a question, share your results, or help someone else.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning