はじめる

YOLO26モデルのTensorRTエクスポート

TensorRTは、高速なディープラーニング推論を実現するNVIDIAのSDKです。Ultralytics YOLO26モデルをformat="engine"でエクスポートすると、ビルドに使用したNVIDIA GPU向けに最適化された.engineファイルが、FP32、FP16、またはINT8の精度で生成されます。

TensorRTエンジンはハードウェアとランタイムに固有です

TensorRTは、エンジンをビルドしたGPU向けに最適化します。デプロイ先のGPU、または同じモデルのGPU上で、同じTensorRTバージョンを使用してエンジンをビルドしてください。.engineファイルは移植可能なモデル形式ではありません。エッジデプロイでは、Ultralytics Platformが8種類のJetsonターゲットを提供しており、それぞれについて実機でのビルドと検証の状況を記載しています。または、デプロイ先のデバイス上でローカルにエクスポートできます。

概要#

プロパティ詳細
format 引数engine(別名: tensorrt、trt)
出力yolo26n.engineは、JSONメタデータヘッダー(クラス名、タスク、画像サイズ)から始まる単一ファイルです。中間ファイルのyolo26n.onnxは、そのファイルと同じ場所に残ります
実行環境データセンター、ワークステーション、Jetsonを含むNVIDIA GPU。Jetson DLAコアも対象です(TensorRT 11では対象外)
ランタイムTensorRT 7.0以降(10.2.0はサポートされていません)
適合率FP32、FP16、INT8
エクスポートホストNVIDIA GPUとCUDAを搭載したマシン。デプロイ先のGPU、または同じモデルのGPU上でビルドしてください
クラウドでエクスポート

Ultralytics Platformでは、選択したGPUタイプ(NVIDIA Jetsonターゲットを含む)でTensorRTエンジンをビルドできるため、ローカルのエクスポート環境は不要です。

クイックスタート#

NVIDIA GPUとCUDAを搭載したマシンにUltralyticsパッケージをインストールしてください。Linuxでは、TensorRT Pythonパッケージが見つからない場合、初回のエクスポート時にCUDAバージョンに適合するパッケージがインストールされます。NVIDIA Jetsonでは、JetPackに同梱されているTensorRTバージョンを使用してください。Windowsでは、エクスポート前にTensorRTを手動でインストールしてください。

pip install ultralytics

ほかのインストール方法については、インストールガイドをご覧ください。次に、モデルをエクスポートし、エクスポート済みエンジンを読み込んで推論を実行するか、精度を検証してください。推論と検証にはNVIDIA GPUが必要です。NVIDIA T4では、YOLO26nエンジンのビルドに1~3分かかります。

エクスポート
from ultralytics import YOLO

# YOLO26モデルを読み込みます
model = YOLO("yolo26n.pt")

# モデルをTensorRT形式にエクスポートします
model.export(format="engine")  # 'yolo26n.engine'を作成します

# または、FP16エンジンをエクスポートします
model.export(format="engine", quantize=16)  # 'yolo26n.engine'を作成します
推論
from ultralytics import YOLO

# エクスポートしたTensorRTモデルを読み込む
model = YOLO("yolo26n.engine")

# 推論を実行
results = model("https://ultralytics.com/images/bus.jpg")
検証
from ultralytics import YOLO

# エクスポートしたTensorRTモデルを読み込む
model = YOLO("yolo26n.engine")

# COCO8データセットで精度を検証します
metrics = model.val(data="coco8.yaml")

対応タスク#

TensorRTエクスポートでは、YOLOv8、YOLO11、YOLO26モデルを使用して、Ultralyticsがサポートする7つすべてのタスクに対応します。検出、セグメンテーション、セマンティックセグメンテーション、深度推定、分類、姿勢推定、OBBです。セマンティックセグメンテーションと深度推定は、これらのヘッドを搭載する唯一のモデルファミリーであるYOLO26のみで利用できます。

エクスポート引数#

引数種類デフォルト説明
formatstr'engine'エクスポートしたモデルのターゲットフォーマットです。さまざまなデプロイ環境との互換性を定義します。
imgszintまたはtuple640モデル入力の画像サイズです。正方形画像の場合は整数、特定のサイズの場合はタプル(height, width)を指定できます。
quantizeintまたはstrNone量子化精度: 16(FP16)または8(INT8/PTQ。キャリブレーション用のdata/fractionが必要)です。32/未設定の場合はFP32です。quantize=8で学習したチェックポイントは、キャリブレーションなしで、保持している範囲からINT8にエクスポートされます。これはquantizeが未設定の場合も同様です。quantize=16またはquantize=32を指定するとエラーになります。非推奨のhalf/int8フラグを置き換えます。
dynamicboolFalseバッチサイズ1~batch、画像サイズ32ピクセル~imgszの2倍を受け付けるエンジンをビルドします。旧型GPU上の動的INT8エンジンでは、最小サイズがより大きくなります。Falseの場合、エンジンが受け付けるのはエクスポート時のbatchとimgszのみです。
simplifyboolTrueonnxslimを使用してモデルグラフを簡素化し、パフォーマンスと互換性を向上させる可能性があります。
opsetintNone中間ONNXグラフのONNX opsetバージョンを指定します。指定しない場合は、opset 18(PyTorch < 2.4ではより低いバージョン)を使用し、インストール済みの onnx のバージョンを上限とします。
workspacefloatまたはNoneNoneエンジンのビルド中にTensorRTが使用するメモリの上限(GiB)です。TensorRTにメモリを自動割り当てさせるには、Noneのままにしてください。
nmsbool、省略可None生の出力(None、既定値)、埋め込みNMS(True)、またはNMSフリーヘッド(False)を選択します。nms=Trueの場合、conf(既定値は0.25)、iou、max_det、agnostic_nmsはエクスポート時に固定されます。nms=Trueはセマンティックモデルと深度モデルでは無視され、分類モデルではエラーになります。
batchint1エンジンのバッチサイズ、またはdynamic=Trueを指定した場合の最大バッチサイズです。INT8キャリブレーションにもこのバッチサイズが使用されます。
datastrNoneINT8キャリブレーションに使用するデータセットのYAMLファイルへのパスです。分類の場合は、データセットディレクトリまたは組み込みデータセット名を指定します。splitが設定されていない場合、キャリブレーションにはデータセットのval分割を使用します。quantize=8を指定していて値を省略した場合、Ultralyticsはモデルタスク用の小規模な既定データセットを使用します。たとえば検出にはcoco8.yamlを使用します。quantize=8で学習したチェックポイントには不要です。
fractionfloat、int、またはlist1.0キャリブレーション用サブセットを、比率、画像数、または[train, val, test]の比率/件数として指定します。2項目のリストではtestがすべて含まれ、0では除外されます。
devicestrNoneエクスポート先のデバイスを指定します。GPU(device=0、未設定時に使用)、またはNVIDIA Jetson向けDLA(device=dla:0またはdevice=dla:1。quantize=16またはquantize=8を指定)です。
JetPackとDLAの互換性

NVIDIA Jetsonでは、Ultralyticsは使用中のJetPackリリースに付属するTensorRTランタイムでエクスポートします。JetPack 7でのエクスポートには、TensorRT 10.15以降かつ11未満が必要です。TensorRT 11では、device=dla:0とdevice=dla:1を指定するとエラーになります。NVIDIAによると、TensorRT 10.7はDLAをサポートする最後の10.xリリースです。また、TensorRT 11.4.1ではJetPack 7.2.2のサポートが追加されていますが、Ultralyticsではまだ使用していません。

すべての形式に共通する引数については、エクスポートモードのドキュメントを参照してください。

INT8量子化でのTensorRTエクスポート#

quantize=8は、学習後量子化(PTQ)を使用してINT8エンジンをビルドします。エクスポート時にキャリブレーション画像をモデルに入力し、各テンソルの値の範囲を測定します。量子化対応学習によってquantize=8でファインチューニングされたチェックポイントには、すでにINT8の範囲が保持されているため、エクスポート時にキャリブレーションは行われません。

quantize引数とdata引数はすべてのTensorRTバージョンで同じですが、quantize=8で学習されていないチェックポイントのエクスポート処理は内部で異なります。

TensorRT 7~10TensorRT 11
INT8方式IInt8Calibratorインターフェースを使用する暗黙的な量子化明示的な量子化: NVIDIA ModelOptがONNXグラフにQ/DQノードを挿入します
キャリブレーションアルゴリズムGPUではMINMAX_CALIBRATION、DLAではENTROPY_CALIBRATION_2CPU上で実行されるModelOptのmax
使用するキャリブレーション画像分割データのすべての完全なバッチシャッフルした約512枚の画像、または小規模な分割データのすべての完全なバッチ
quantize=8を指定したdynamic=Trueテスト対象外です。dynamic=Trueを指定せずにエクスポートしてくださいサポート対象
FP16(quantize=16)TensorRTビルダーのフラグModelOptのAutoCastによる混合精度変換

初回使用時にModelOptがインストールされます。Ultralyticsはキャリブレーションキャッシュを再利用しないため、エクスポートのたびにキャリブレーションが再実行されます。2つの方式の詳細については、TensorRTドキュメントの量子化型の使用をご覧ください。

quantize=8で学習していないチェックポイントの場合は、dataを使用してキャリブレーション画像を渡してください。たとえばdata="my_dataset.yaml"のように指定します。splitを設定しない限り、そのデータセットのval分割をキャリブレーションに使用します。また、fractionで画像数を制限できます。NVIDIAはデプロイ環境を代表する500枚以上の画像を推奨しており、エクスポート時には300枚未満の場合に警告が記録されます。dataを指定しない場合、エクスポート時に警告が記録され、モデルタスク用の小規模なサンプルデータセットが使用されます。たとえば検出にはcoco8.yamlが使用されます。このデータセットの検証分割には4枚の画像があり、エクスポートのテストには十分ですが、デプロイ用モデルのキャリブレーションには不十分です。

例
from ultralytics import YOLO

model = YOLO("yolo26n.pt")

# COCOの検証画像の10%(500枚)でキャリブレーションします。coco.yamlを独自のデータセットに置き換えてください
model.export(format="engine", quantize=8, data="coco.yaml", fraction=0.1)

# エクスポート済みのINT8エンジンを読み込み、推論を実行します
model = YOLO("yolo26n.engine")
result = model.predict("https://ultralytics.com/images/bus.jpg")

ベンチマーク用GPUでは、INT8エンジンはFP32エンジンより1.04~2.3倍高速でしたが、FP16エンジンより高速だったのは10モデル中3モデルのみでした。INT8ではYOLO26nからYOLO26lでmAPが1.7~2.9低下し、YOLO26xとYOLO26n-poseではさらに大きく低下しました。YOLO26nのINT8エンジンはFP32エンジンより大きく(11 MBに対して30 MB)、一方、大型モデルは小さくなりました(YOLO26lでは103 MBに対して53 MB)。INT8では信頼度の値も変化する場合があるため、INT8エンジン独自のF1曲線をもとに信頼度しきい値を選択してください。すべてのモデルについては、ベンチマークをご覧ください。

出力形式#

エンジンはimagesという名前の入力を1つ受け取り、元になったONNXエクスポートと同じ出力を返します。ただし、TensorRT 10より前のバージョンでは、セマンティックモデルはuint8クラスマップの代わりに、形状が(batch, classes, height, width)の浮動小数点クラススコアを返します。各タスクとnmsの各設定における出力形状については、ONNX出力形式をご覧ください。

Ultralytics以外でエンジンを読み込む#

Ultralyticsの.engineファイルは、通常のTensorRTエンジンではありません。4バイトのリトルエンディアン長、その長さ分のJSONメタデータ、シリアライズされたエンジンの順に格納されています。TensorRTのdeserialize_cuda_engineにファイル全体を渡すと、Noneが返されます。ヘッダーを読み飛ばして、TensorRT APIでエンジンを読み込んでください。

import json

import tensorrt as trt

with open("yolo26n.engine", "rb") as f:
    n = int.from_bytes(f.read(4), byteorder="little")  # メタデータヘッダーの長さ
    metadata = json.loads(f.read(n))  # クラス名、タスク、imgsz、バッチサイズ、エクスポート引数
    engine = trt.Runtime(trt.Logger(trt.Logger.WARNING)).deserialize_cuda_engine(f.read())

別のツールが通常のTensorRTエンジンファイルを必要とする場合は、ヘッダーの後のバイト列を新しいファイルに書き込むか、エクスポート時にエンジンと同じ場所に残されるyolo26n.onnxファイルを使って、そのツールでエンジンをビルドしてください。TensorRT 11では、FP16エクスポートとキャリブレーション済みINT8エクスポートで、yolo26n.fp16.onnxとyolo26n.int8.onnxも残されます。別のツールでINT8エンジンをビルドするには、.int8.onnxファイルを使用してください。quantize=8で学習したチェックポイントの場合、yolo26n.onnxにはすでにQ/DQノードが含まれており、.int8.onnxファイルは書き込まれません。TensorRT 11では、このエクスポートによってyolo26n.fp16.onnxが残されます。これは、ほかのレイヤーがFP16の同じQ/DQグラフです。

デプロイする#

YOLO("yolo26n.engine")は、TensorRT Pythonランタイムでエンジンを読み込みます。device="cpu"を渡した場合も含め、エンジンは既定でGPU 0上で実行されます。同じモデルの別のGPUで実行するには、device=1を渡してください。device=dla:0またはdevice=dla:1でエクスポートしたエンジンは、そのDLAコア上で実行されます。

dynamic=Trueを指定せずにエクスポートしたエンジンの入力形状は固定です。predictとvalでは、エクスポート時のimgszが使用され、異なるimgsz引数は無視されます。Ultralyticsは、大きなバッチをエクスポート時のサイズのバッチに分割し、小さなバッチにはパディングを行うため、任意の枚数の画像を処理できます。dynamic=Trueでエクスポートしたエンジンは、範囲内のあらゆるバッチサイズと画像サイズを受け付け、範囲外の形状に対してValueError: input size ... is outside the TensorRT optimization profileを発生させます。nms=Trueを指定すると、範囲を超えるバッチはエクスポート時のサイズのバッチに分割されます。

デプロイガイド#

制限事項とトラブルシューティング#

  • エンジンは移植できません: エンジンは特定のGPUモデルとTensorRTバージョン向けにビルドされます。GPU、TensorRTバージョン、またはJetPackリリースを変更する場合は、エンジンを再ビルドしてください。エンジンを読み込めない場合、UltralyticsはTensorRT model exported with a different version than expectedをログに記録します。
  • GPUが必要です: deviceが未設定の場合、エクスポートにはdevice=0が使用されます。また、device=cpuに対してexport running on CPU but must be on GPUが発生します。
  • ほかのツールではエンジンを読み込めません: .engineファイルはメタデータヘッダーから始まるため、TensorRT APIで直接読み取ることはできません。Ultralytics以外でエンジンを読み込むをご覧ください。
  • TensorRTバージョン: UltralyticsにはTensorRT 7.0.0以降が必要です。TensorRT 10.2.0はサポート対象外で、自動インストールでもスキップされます。JetPack 7とNVIDIA DGXシステムでのエクスポートにはTensorRT 10.15以降が必要です(Jetsonでは11未満)。インストール済みバージョンがこの範囲外の場合、エクスポート時にインストールが試みられます。
  • 古いTensorRTでのNMSフリーヘッド: TensorRT 8.5.0より前のバージョンでは、YOLO26のNMSフリーヘッドをビルドできません。エクスポート時に警告が記録され、NMSが必要な生の予測が書き込まれます。nms=Falseを指定してエクスポートするには、TensorRT 8.5.0以降にアップグレードしてください。
  • JetPack 6でのINT8: JetPack 6上のTensorRT 10.3.0では、nms=Trueを指定したINT8エクスポートは失敗し、nms=Falseを指定したINT8エクスポートは生の予測にフォールバックします。解決方法については、Jetsonガイドをご覧ください。
  • TensorRT 10.16でのINT8: TensorRT 10.16.1でのINT8エクスポートは、NVIDIA RTX PRO 6000 BlackwellとRTX 6000DのGPUでCould not find any implementation for nodeにより失敗しました。RTX PRO 6000 Blackwellでは、TensorRT 10.13、10.14、10.15、11.4でINT8エンジンをビルドできました。
  • DLA: device=dla:0とdevice=dla:1は、NVIDIA Jetsonでのみ、かつquantize=16またはquantize=8を使用する場合にのみ動作します。TensorRT 11ではエクスポート時にエラーが発生します。DLAがサポートしないレイヤーはGPU上で実行されます。
  • 動的形状: dynamic=Trueでは最大バッチサイズが必要なため、batchも設定してください。たとえばbatch=8のように指定します。設定しない場合は警告が記録され、最大バッチサイズは1になります。エンジンはバッチサイズ1~batch、画像サイズ32ピクセル~エクスポート時のimgszの2倍を受け付けます。たとえばimgsz=320 batch=4でエクスポートしたエンジンは640ピクセルで実行できますが、704ピクセルやバッチサイズ6ではinput size ... is outside the TensorRT optimization profileが発生します。dynamic=Trueとquantize=8を組み合わせて使用できるのはTensorRT 11のみです。T4など、コンピュートケイパビリティ7.5以下のGPUでは、動的INT8エンジンの最小サイズは64ピクセルです(P6モデルでは128ピクセル)。
  • 入力サイズ固定: dynamic=Trueを指定せずにエクスポートしたエンジンは、常にエクスポート時のimgszで実行されます。predictまたはvalに別のimgszを渡しても効果はありません。入力サイズを変更するには、再エクスポートしてください。
  • dataを指定しないINT8エクスポート: チェックポイントがquantize=8で学習されていない場合、エクスポート時にタスク用の小規模な既定データセットでキャリブレーションが行われます。このデータセットには検出用の検証画像が4枚しかなく、警告が記録されます。代表的な画像をdataで渡してください。300枚未満の場合、エクスポート時に警告が記録されます。
  • 初回の推論が遅い: 新しいエンジンを使用するとき、または動的エンジンで新しいimgszを使用するときは、最初の数回の呼び出しに、以降の呼び出しより時間がかかります。

その他のエラーについては、よくある問題のガイドを参照してください。

ベンチマーク#

YOLO26モデルページには、セマンティックセグメンテーション以外のすべてのタスクについて、NVIDIA T4 GPUで測定した各モデルのTensorRT 10の速度が掲載されています。

FP32、FP16、INT8の比較#

以下の表では、すべてのYOLO26検出モデルと、ほかの5つのタスクにおけるYOLO26nモデルについて、PyTorchとFP32、FP16、INT8のTensorRT 11.4エンジンを比較しています。すべての値は、1台のNVIDIA RTX PRO 6000 Blackwell Server Edition GPUで測定しました。

画像あたりのミリ秒数です。値が小さいほど高速です。各モデルで最速の形式を太字で示しています。YOLO26xのINT8エンジンは精度が不安定だったため除外しています。

モデルimgszPyTorchTensorRT FP32TensorRT FP16TensorRT INT8
YOLO26n6402.850.670.480.53
YOLO26s6402.981.150.610.66
YOLO26m6403.292.221.031.08
YOLO26l6404.703.031.491.43
YOLO26x6405.934.312.091.84
YOLO26n-seg6403.180.930.650.72
YOLO26n-sem10241.740.740.450.71
YOLO26n-cls2241.750.290.240.20
YOLO26n-pose6403.390.760.510.59
YOLO26n-obb10244.551.030.640.88
  • FP16では、すべてのモデルでFP32の精度が0.1ポイント以内に保たれました。検出モデルでは、FP32エンジンより1.4~2.2倍、PyTorchより2.8~5.9倍高速に動作しました。
  • INT8は検出モデルでFP16のレイテンシの12%以内で動作し、YOLO26n、YOLO26s、YOLO26m、YOLO26lではmAPが1.7~2.9低下しました。このGPUでは、YOLO26l、YOLO26x、YOLO26n-clsでのみFP16より高速でした。
  • YOLO26x INT8の精度は、3つのビルドでFP32の57.5に対して25.3~38.5 mAPまで低下しました。YOLO26n-pose INT8では、pose mAPが56.7から33.4に低下しました。デプロイする前に、各INT8エンジンを必ず独自のデータで検証してください。
  • TensorRT 10.16のYOLO26nおよびYOLO26sのFP32エンジンとFP16エンジンは、TensorRT 11.4と同等の精度でした。FP16エンジンは約7%高速で、FP32エンジンはTensorRT 11.4の場合より4%~9%低速でした。

NVIDIA JetsonとDGX Sparkについては、JetsonのベンチマークとDGX Sparkガイドをご覧ください。

2026年11月13日にultralytics 8.4.211、TensorRT 11.4.0、PyTorch 2.15.0、CUDA 13.2を使用し、batch=1で測定しました。レイテンシはvalが報告する推論ステージの値であり、前処理と後処理は含みません。

TensorRTについて#

TensorRTは、レイヤーを融合し、ビルドに使用するGPU上で各レイヤーに最速のカーネルを選択し、必要に応じて精度をFP16またはINT8に下げてエンジンを構築します。詳しくは、TensorRTのドキュメントをご覧ください。

NVIDIA TensorRT connecting deep learning frameworks to NVIDIA data center GPUs, Jetson, and DLA hardware

よくある質問#

  • 同じTensorRTバージョンを使用する同一モデルのGPUでのみ実行できます。エンジンは、特定のGPUモデルとTensorRTバージョン向けにビルドされます。異なるハードウェア間で1つのファイルを共有するには、ONNXにエクスポートし、各デバイスでエンジンをビルドしてください。NVIDIA Jetsonでは、Ultralytics Platformを使って8種類のJetsonターゲット向けにエンジンをビルドできます。

  • まずFP16(quantize=16)をお試しください。キャリブレーションデータは不要で、FP32の精度を維持できます。TensorRT 11.4を搭載したNVIDIA RTX PRO 6000 Blackwellでのベンチマークでは、同じ48.5 mAP検証 50-95で、FP16によりYOLO26sのレイテンシが画像あたり1.15 msから0.61 msに短縮されました。INT8(quantize=8)は0.66 ms、46.3 mAP検証 50-95で動作したため、このGPUではFP16より高速ではなく、チェックポイントがquantize=8を使って学習されていない場合は、代表的なキャリブレーションデータが必要です。INT8はほかのハードウェアでは有効な場合があります。Jetsonのベンチマークには、組み込みデバイスでのFP16とINT8の結果が掲載されています。INT8を選択する前に、デプロイ先のデバイスで両方の精度を測定してください。

  • dynamic=Trueを指定してエクスポートし、batchに実行予定の最大バッチサイズを設定してください。これにより、エンジンは1からbatchまでのバッチと、32ピクセルからエクスポート時のimgszの2倍までの画像サイズを受け付けます。ただし、古いGPUでの動的INT8エンジンでは最小値が高くなります。dynamic=Trueを指定しない場合、エンジンの入力形状は固定され、Ultralyticsは各バッチをその形状に合わせて分割またはパディングします。

    動的エンジン
    from ultralytics import YOLO
    
    model = YOLO("yolo26n.pt")
    model.export(format="engine", dynamic=True, batch=8, quantize=16)
    
    model = YOLO("yolo26n.engine")
    results = model(["https://ultralytics.com/images/bus.jpg"] * 4, batch=4)  # 画像4枚のバッチ
  • JetPackリリースに含まれるTensorRTバージョンを使用し、Jetson上でエクスポートを実行してください。DLAコアを使用するには、quantize=16またはquantize=8とともにdevice=dla:0を追加します。セットアップとベンチマークについては、NVIDIA Jetsonガイドをご覧ください。

    Jetson上でエクスポート
    from ultralytics import YOLO
    
    model = YOLO("yolo26n.pt")
    model.export(format="engine", quantize=16)  # Jetson GPU上のFP16エンジン
    
    # または、代わりにDLAコア0向けのFP16エンジンをビルドします
    model.export(format="engine", quantize=16, device="dla:0")
  • Triton Inference Serverガイドでは、モデルをONNXにエクスポートし、config.pbtxtでTritonのTensorRTアクセラレーターを有効にします。Tritonは初回ロード時にサーバーGPU上でTensorRTエンジンをビルドしてキャッシュするため、エンジンは常にサーバーのGPUとTensorRTバージョンに適合します。このガイドでは、モデルリポジトリの構成、サーバーコンテナ、Ultralyticsを使ったクライアント推論について説明します。

コメント116

質問したり、結果を共有したり、ほかの人をサポートしたりできます。

  1. AgbajeAyomipoGitHub

    Hi Ultralytics team, I’ve trained a YOLOv11 model on (1024x1024) images from a camera feed and now I’m trying to run real-time inference on live streams using a Jetson Orin Nano. I want to maintain full resolution for inference because of accuracy requirements, but currently I'm getting only 1-2 FPS. When I reduce the input size, the FPS improves significantly, but it's not acceptable due to missed detections at lower resolutions. I attempted to export the model to TensorRT using:

    model.export(format="engine", imgsz=(2592, 1944), half=True) but it fails silently. If I use a dynamic=true without specifying the imgsz parameter, the export succeeds and uses (1024, 1024). My questions:

    Is TensorRT export for such high-resolution input supported/recommended with YOLOv11? If not, is there any known limitation or workaround? Are there ways to improve performance with high-res inference on Jetson Orin Nano? What hardware would you recommend for real-time inference on 1-3 camera streams with 5MP inputs, assuming we need at least ~15-20 FPS per stream? Device: AAEON BOXER-8621AI Module: NVIDIA® Jetson Orin Nano™ (4GB LPDDR5, Super Mode Enabled) Memory: 4 GB LPDDR5 I/O: USB 3.2 Gen 2, M.2 Expansion Operating System: JetPack 5.1.4 (L4T 35.6.0, Ubuntu 20.04) Use Case: Real-time multi-stream 5MP video inference

    1
  2. AgbajeAyomipoGitHub

    Hi Ultralytics team, I’ve trained a YOLOv11 model on full-size 5MP (2592x1944) images from a camera feed and now I’m trying to run real-time inference on live streams using a Jetson Orin Nano. I want to maintain full resolution for inference because of accuracy requirements, but currently I'm getting only 1-2 FPS. When I reduce the input size, the FPS improves significantly, but it's not acceptable due to missed detections at lower resolutions. I attempted to export the model to TensorRT using:

    model.export(format="engine", imgsz=(2592, 1944), half=True) but it fails silently. If I use a dynamic=true, the export succeeds and uses (1024, 1024). My questions:

    1. Is TensorRT export for such high-resolution input supported/recommended with YOLOv11? If not, is there any known limitation or workaround?
    2. Are there ways to improve performance with high-res inference on Jetson Orin Nano?
    3. What hardware would you recommend for real-time inference on 1-3 camera streams with 5MP inputs, assuming we need at least ~15-20 FPS per stream? Device: AAEON BOXER-8621AI Module: NVIDIA® Jetson Orin Nano™ (4GB LPDDR5, Super Mode Enabled) Memory: 4 GB LPDDR5 I/O: USB 3.2 Gen 2, M.2 Expansion Operating System: JetPack 5.1.4 (L4T 35.6.0, Ubuntu 20.04) Use Case: Real-time multi-stream 5MP video inference
    1
  3. 020423lzlGitHub

    m的模型大小比n大的多,速度也慢了很多,输入图像尺寸越大,越吃显存,速度也越慢

    李子乐控制工程 @.***

    ---Original--- From: @.> Date: Sat, May 9, 2026 10:30 AM To: @.>; Cc: @.@.>; Subject: Re: [ultralytics/ultralytics] zh/integrations/tensorrt/ (Discussion #9868)

    现在有一个奇怪的现象,我导出的tensorrt模型的推理速度几乎和原来的.pt几乎没有差别甚至更慢,并且导出的tensorrt模型的推理结果和.pt模型的差别很大。 我的设备是i914900k+64G RAM+RTX A6000 我的环境是cuda12.4.131+tensorrt10.10.0.31+torch2.5.1+ultralytics8.3.252 导出命令: yolo export model=yolo11m.pt imgsz=1280 format='engine 推理代码为: model.predict(stream_path, imgsz=1280, classes=[14], conf=0.2, iou=0.5, stream=True, task='detect')

    另外我试了下yolo11n.pt的640输入尺寸导出,推理速度就有明显提升,当然推理结果差别仍然较大。 请问这是什么道理,有什么解决办法?

    — Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.Message ID: @.***>

    1. User

      能不能读完再说话,肯定是m和m比,n和n比,同样尺寸输入和同样尺寸输入的比啊。 该显卡的RT core算力是普通fp32算力的近两倍。

    2. Glenn JocherUltralytics

      是的,性能应当在同一模型、同一 imgsz、同一 batch、同一后处理参数下比较;m 比 n 更大、1280 比 640 更吃显存且更慢是正常现象。对 RTX A6000 来说,FP32 的 TensorRT 往往不会比 .pt 明显更快,建议先按 TensorRT 导出文档 用 half=True 重新导出,并在相同输入上预热后再统计平均耗时;如果 engine 与 .pt 结果仍明显不一致,请贴出 !yolo checks、完整控制台日志文本和一个最小可复现示例,我们好继续排查环境或后处理差异。

  4. User

    现在有一个奇怪的现象,我导出的tensorrt模型的推理速度几乎和原来的.pt几乎没有差别甚至更慢,并且导出的tensorrt模型的推理结果和.pt模型的差别很大。 我的设备是i914900k+64G RAM+RTX A6000 我的环境是cuda12.4.131+tensorrt10.10.0.31+torch2.5.1+ultralytics8.3.252 导出命令: yolo export model=yolo11m.pt imgsz=1280 format='engine 推理代码为:

    model.predict(stream_path, imgsz=1280, classes=[14], conf=0.2, iou=0.5, stream=True, task='detect')

    另外我试了下yolo11n.pt的640输入尺寸导出,推理速度就有明显提升,当然推理结果差别仍然较大。 请问这是什么道理,有什么解决办法?

  5. 020423lzlGitHub

    etson@yahboom:~/ultralytics/ultralytics$ yolo predict model=best.engine source=0 save=False show WARNING ⚠️ Unable to automatically guess model task, assuming 'task=detect'. Explicitly define task for your model, i.e. 'task=detect', 'segment', 'classify','pose' or 'obb'. Ultralytics 8.3.172 🚀 Python-3.10.12 torch-2.5.0a0+872d972e41.nv24.08 CUDA:0 (Orin, 7620MiB) Loading best.engine for TensorRT inference... [12/18/2025-17:11:05] [TRT] [I] Loaded engine size: 75 MiB [12/18/2025-17:11:05] [TRT] [I] [MS] Running engine with multi stream info [12/18/2025-17:11:05] [TRT] [I] [MS] Number of aux streams is 7 [12/18/2025-17:11:05] [TRT] [I] [MS] Number of total worker streams is 8 [12/18/2025-17:11:05] [TRT] [I] [MS] The main stream provided by execute/enqueue calls is the first worker stream [12/18/2025-17:11:05] [TRT] [I] [MemUsageChange] TensorRT-managed allocation in IExecutionContext creation: CPU +1, GPU +88, now: CPU 1, GPU 158 (MiB)

    [ WARN:0@2.771] global cap_gstreamer.cpp:1777 open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1 1/1: 0... Success ✅ (inf frames of shape 1920x1080 at 5.00 FPS)

    Traceback (most recent call last): File "/home/jetson/.local/bin/yolo", line 7, in sys.exit(entrypoint()) File "/home/jetson/Downloads/ultralytics-main/ultralytics/cfg/init.py", line 983, in entrypoint getattr(model, mode)(**overrides) # default args from model File "/home/jetson/Downloads/ultralytics-main/ultralytics/engine/model.py", line 555, in predict return self.predictor.predict_cli(source=source) if is_cli else self.predictor(source=source, stream=stream) File "/home/jetson/Downloads/ultralytics-main/ultralytics/engine/predictor.py", line 247, in predict_cli for _ in gen: # sourcery skip: remove-empty-nested-block, noqa File "/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py", line 36, in generator_context response = gen.send(None) File "/home/jetson/Downloads/ultralytics-main/ultralytics/engine/predictor.py", line 351, in stream_inference s[i] += self.write_results(i, Path(paths[i]), im, s) File "/home/jetson/Downloads/ultralytics-main/ultralytics/engine/predictor.py", line 434, in write_results string += f"{result.verbose()}{result.speed['inference']:.1f}ms" File "/home/jetson/Downloads/ultralytics-main/ultralytics/engine/results.py", line 694, in verbose return "".join(f"{n} {self.names[i]}{'s' * (n > 1)}, " for i, n in enumerate(counts) if n > 0) File "/home/jetson/Downloads/ultralytics-main/ultralytics/engine/results.py", line 694, in return "".join(f"{n} {self.names[i]}{'s' * (n > 1)}, " for i, n in enumerate(counts) if n > 0) KeyError: 171 terminate called without an active exception Aborted (core dumped) jetson@yahboom:~/ultralytics/ultralytics$ How to solve it

    1. Glenn JocherUltralytics

      KeyError: 171 表示模型输出了类别 171,但当前 names 里没有这个索引(通常是自定义数据集的标签类别编号不在 0..nc-1 范围内、data.yaml 里的 names 数量与 nc 不匹配,或导出/推理用的模型与数据配置不一致导致的元数据错配);请先把所有标注 .txt 的 class id 修正为连续的 0..nc-1,同步修正 data.yaml 的 nc/names,修正后删除数据集 labels/ 下的 *.cache,再用同一套环境从 best.pt 重新导出 .engine(参考 TensorRT 导出文档),并在推理时显式加上 task=detect。另外请把下面命令的完整输出(文本)贴在这个 discussion 里,以及你当时的导出命令,方便我们确认是否有多环境/路径冲突:

      yolo checks
    2. 020423lzlGitHub

      Thank you for your reply. The issue has been resolved. I was using the RT-DETR model, but I mistakenly used "from ultralytics import YOLO" when exporting

    3. Glenn JocherUltralytics

      Glad you found it — RT-DETR models should be loaded/exported with RTDETR(...) (mixing them with YOLO(...) can produce mismatched metadata like names), see the RT-DETR model docs for details:

      from ultralytics import RTDETR
      
      model = RTDETR("best.pt")
      model.export(format="engine")  # creates best.engine
  6. fly2skyToEnjoyGitHub

    May I ask : The following command exports the file, whether the box and mask are both nmsed at the same time ???

    from ultralytics import YOLO

    Load the YOLO11 model

    model = YOLO("yolo11n.pt")

    Export the model to TensorRT format

    model.export(format="engine") # creates 'yolo11n.engine'

    Load the exported TensorRT model

    tensorrt_model = YOLO("yolo11n.engine")

    Run inference

    results = tensorrt_model("https://ultralytics.com/images/bus.jpg")

  7. dilanpatel195GitHub

    I am trying to prediction model for the YOLOv11n-seg, I have exported the .py to .engine to back it run faster but keep getting a KEY error message:


    KeyError Traceback (most recent call last) Cell In[4], line 109 106 # Inside the main loop after grabbing a frame 107 if inference_active and not inpainting_active: 108 # Perform YOLO inference --> 109 results = model(rgb_frame)[0] 110 masked_image = rgb_frame.copy() # Make a copy for masking 112 # Process YOLO masks (original functionality remains unchanged)

    File c:\ProgramData\miniconda3\Lib\site-packages\ultralytics\engine\model.py:176, in Model.call(self, source, stream, **kwargs) 147 def call( 148 self, 149 source: Union[str, Path, int, Image.Image, list, tuple, np.ndarray, torch.Tensor] = None, 150 stream: bool = False, 151 **kwargs, 152 ) -> list: 153 """ 154 Alias for the predict method, enabling the model instance to be callable for predictions. 155 (...) 174 ... print(f"Detected {len(r)} objects in image") 175 """ --> 176 return self.predict(source, stream, **kwargs)

    File c:\ProgramData\miniconda3\Lib\site-packages\ultralytics\engine\model.py:554, in Model.predict(self, source, stream, predictor, **kwargs) 552 if prompts and hasattr(self.predictor, "set_prompts"): # for SAM-type models 553 self.predictor.set_prompts(prompts) --> 554 return self.predictor.predict_cli(source=source) if is_cli else self.predictor(source=source, stream=stream)

    File c:\ProgramData\miniconda3\Lib\site-packages\ultralytics\engine\predictor.py:168, in BasePredictor.call(self, source, model, stream, *args, **kwargs) 166 return self.stream_inference(source, model, *args, **kwargs) 167 else: --> 168 return list(self.stream_inference(source, model, *args, **kwargs))

    File c:\ProgramData\miniconda3\Lib\site-packages\torch\utils_contextlib.py:36, in _wrap_generator..generator_context(*args, **kwargs) 33 try: 34 # Issuing None to a generator fires it up 35 with ctx_factory(): ---> 36 response = gen.send(None) 38 while True: 39 try: 40 # Forward the response to our caller and get its next request

    File c:\ProgramData\miniconda3\Lib\site-packages\ultralytics\engine\predictor.py:274, in BasePredictor.stream_inference(self, source, model, *args, **kwargs) 268 self.results[i].speed = { 269 "preprocess": profilers[0].dt * 1e3 / n, 270 "inference": profilers[1].dt * 1e3 / n, 271 "postprocess": profilers[2].dt * 1e3 / n, 272 } 273 if self.args.verbose or self.args.save or self.args.save_txt or self.args.show: --> 274 s[i] += self.write_results(i, Path(paths[i]), im, s) 276 # Print batch results 277 if self.args.verbose:

    File c:\ProgramData\miniconda3\Lib\site-packages\ultralytics\engine\predictor.py:334, in BasePredictor.write_results(self, i, p, im, s) 332 result = self.results[i] 333 result.save_dir = self.save_dir.str() # used in other locations --> 334 string += f"{result.verbose()}{result.speed['inference']:.1f}ms" 336 # Add predictions to image 337 if self.args.save or self.args.show:

    File c:\ProgramData\miniconda3\Lib\site-packages\ultralytics\engine\results.py:663, in Results.verbose(self) 661 for c in boxes.cls.unique(): 662 n = (boxes.cls == c).sum() # detections per class --> 663 log_string += f"{n} {self.names[int(c)]}{'s' * (n > 1)}, " 664 return log_string

    KeyError: 2

    Any help would be greatly appreciated!

  8. Ranjith3436GitHub

    Now, My TensorRT Sengment model used for track. if any detections not there the processing FPS is 75-80 in jetson. But once the person or people detected suddenly reused to 15-20. processing time going to 40ms. only when the object detected. What's the issue in model.track(), could i run all the tracking thing on GPU.

    1. Glenn JocherUltralytics(編集済み)

      @Ranjith3436 the performance drop when objects are detected is expected behavior, as tracking introduces additional computational overhead. When objects are detected, the model.track() method performs several CPU-bound operations including feature extraction, association, and trajectory management.

      To improve performance:

      1. Try using a smaller model variant (like YOLO26n-seg instead of larger variants)
      2. Consider reducing the image resolution for tracking
      3. Optimize tracking parameters by setting persist=True and adjusting conf thresholds higher to track fewer objects
      4. Use half=True (FP16) or int8=True when exporting your model to TensorRT for maximum GPU acceleration

      For the tracking components specifically, the BoT-SORT or ByteTrack algorithms used by Ultralytics do have some CPU-bound operations, but you can minimize their impact with the above optimizations. For more details on tracking optimization, check our tracking documentation.

      1
  9. Ranjith3436GitHub

    I convert Classification model that i retrained. But it throw the error "amax(): Expected reduction dim 1 to have non-zero size."

    1. Glenn JocherUltralytics

      @Ranjith3436 this error typically occurs when TensorRT encounters an empty dimension during model conversion. For classification models, this could happen if:

      1. Your model architecture was modified or if you're using a custom architecture
      2. There might be an issue with batch normalization layers during export
      3. The class count in your retrained model might be causing dimension mismatches

      Try these solutions:

      • Ensure your model's forward pass works correctly before export
      • Try exporting with simplify=False to preserve the original graph structure
      • Check if your classification model has the correct output dimension for your number of classes

      If the issue persists, share more details about your model architecture and export command for better assistance. For more guidance, refer to our TensorRT integration documentation.

    2. Ranjith3436GitHub

      The model trained use yolov8l-cls.pt and the error come from jetson device.

      (model): ClassificationModel( (model): Sequential( (0): Conv( (conv): Conv2d(3, 64, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) (bn): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (1): Conv( (conv): Conv2d(64, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) (bn): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (2): C2f( (cv1): Conv( (conv): Conv2d(128, 128, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (cv2): Conv( (conv): Conv2d(320, 128, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (m): ModuleList( (0-2): 3 x Bottleneck( (cv1): Conv( (conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (cv2): Conv( (conv): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) ) ) ) (3): Conv( (conv): Conv2d(128, 256, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) (bn): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (4): C2f( (cv1): Conv( (conv): Conv2d(256, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (cv2): Conv( (conv): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (m): ModuleList( (0-5): 6 x Bottleneck( (cv1): Conv( (conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (cv2): Conv( (conv): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) ) ) ) (5): Conv( (conv): Conv2d(256, 512, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) (bn): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (6): C2f( (cv1): Conv( (conv): Conv2d(512, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (cv2): Conv( (conv): Conv2d(2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (m): ModuleList( (0-5): 6 x Bottleneck( (cv1): Conv( (conv): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (cv2): Conv( (conv): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) ) ) ) (7): Conv( (conv): Conv2d(512, 1024, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) (bn): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (8): C2f( (cv1): Conv( (conv): Conv2d(1024, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (cv2): Conv( (conv): Conv2d(2560, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (m): ModuleList( (0-2): 3 x Bottleneck( (cv1): Conv( (conv): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (cv2): Conv( (conv): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) ) ) ) (9): Classify( (conv): Conv( (conv): Conv2d(1024, 1280, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn): BatchNorm2d(1280, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (act): SiLU(inplace=True) ) (pool): AdaptiveAvgPool2d(output_size=1) (drop): Dropout(p=0.0, inplace=True) (linear): Linear(in_features=1280, out_features=2, bias=True) ) ) ) )

      model architecture