コンテンツへスキップ

モデル・エクスポートUltralytics YOLO

Ultralytics YOLO エコシステムと統合

はじめに

The ultimate goal of training a model is to deploy it for real-world applications. Export mode in Ultralytics YOLO11 offers a versatile range of options for exporting your trained model to different formats, making it deployable across various platforms and devices. This comprehensive guide aims to walk you through the nuances of model exporting, showcasing how to achieve maximum compatibility and performance.



見るんだ: How To Export Custom Trained Ultralytics YOLO Model and Run Live Inference on Webcam.

Why Choose YOLO11's Export Mode?

  • 汎用性: ONNX,TensorRT,CoreML, などを含む複数のフォーマットにエクスポート。
  • パフォーマンス: TensorRT でGPU を最大 5 倍、ONNX またはOpenVINO でCPU を最大 3 倍高速化。
  • 互換性:多数のハードウェアおよびソフトウェア環境において、モデルを普遍的に展開できるようにします。
  • 使いやすさ:シンプルなCLI 、Python APIにより、素早く簡単にモデルをエクスポートできます。

エクスポート・モードの主な特徴

ここでは、目立った機能をいくつか紹介しよう:

  • ワンクリックエクスポート:簡単なコマンドで様々なフォーマットにエクスポートできます。
  • バッチエクスポート:バッチ推論可能なモデルをエクスポートします。
  • 最適化された推論:エクスポートされたモデルは、推論時間を短縮するために最適化されています。
  • チュートリアルビデオ:スムーズな書き出しのための詳細なガイドとチュートリアル。

チップ

  • 輸出先 ONNXまたは OpenVINOにエクスポートすると、CPU が最大3倍高速化されます。
  • にエクスポートする。 TensorRTにエクスポートすると、GPU が最大5倍高速化されます。

使用例

Export a YOLO11n model to a different format like ONNX or TensorRT. See the Arguments section below for a full list of export arguments.

from ultralytics import YOLO

# Load a model
model = YOLO("yolo11n.pt")  # load an official model
model = YOLO("path/to/best.pt")  # load a custom trained model

# Export the model
model.export(format="onnx")
yolo export model=yolo11n.pt format=onnx  # export official model
yolo export model=path/to/best.pt format=onnx  # export custom trained model

論争

この表は、YOLO のモデルをさまざまなフォーマットにエクスポートする際に利用できる設定とオプションの詳細を示しています。これらの設定は、エクスポートされたモデルのパフォーマンス、サイズ、さまざまなプラットフォームや環境での互換性を最適化するために重要です。適切な設定を行うことで、モデルが最適な効率で目的のアプリケーションに展開できるようになります。

議論タイプデフォルト説明
formatstr'torchscript'エクスポートされるモデルのターゲットフォーマット。 'onnx', 'torchscript', 'tensorflow'など、さまざまな展開環境との互換性を定義している。
imgszint または tuple640モデル入力に必要な画像サイズ。正方形画像の場合は整数,正方形画像の場合はタプルになります. (height, width) 具体的な寸法については
kerasboolFalseEnables export to Keras format for TensorFlow SavedModel, providing compatibility with TensorFlow serving and APIs.
optimizeboolFalseTorchScript へのエクスポート時にモバイルデバイス向けの最適化を適用し、モデルサイズを縮小してパフォーマンスを向上させる可能性があります。
halfboolFalseFP16(半精度)量子化を有効にし、モデルサイズを縮小し、サポートされているハードウェアでの推論を高速化する可能性があります。
int8boolFalseActivates INT8 quantization, further compressing the model and speeding up inference with minimal accuracy loss, primarily for edge devices.
dynamicboolFalseONNX 、TensorRT 、OpenVINO エクスポートのための動的な入力サイズを可能にし、さまざまな画像寸法を扱う柔軟性を高めます。
simplifyboolTrueのモデルグラフを簡略化します。 ONNX エクスポート onnxslimこれにより、パフォーマンスと互換性が向上する可能性があります。
opsetintNone異なるONNX パーサーやランタイムとの互換性のために、ONNX のオペセットのバージョンを指定します。設定されていない場合は、サポートされている最新のバージョンを使用します。
workspacefloat4.0TensorRT 、メモリ使用量とパフォーマンスのバランスをとりながら最適化するために、ワークスペースの最大サイズをGiB単位で設定します。
nmsboolFalse正確で効率的な検出の後処理に不可欠な非最大抑制(NMS)をCoreML エクスポートに追加します。
batchint1エクスポート モデルのバッチ推論サイズ、またはエクスポートされたモデルが同時に処理する画像の最大数を指定します predict モードだ。

Adjusting these parameters allows for customization of the export process to fit specific requirements, such as deployment environment, hardware constraints, and performance targets. Selecting the appropriate format and settings is essential for achieving the best balance between model size, speed, and accuracy.

輸出フォーマット

Available YOLO11 export formats are in the table below. You can export to any format using the format 引数、すなわち format='onnx' または format='engine'.エクスポートされたモデルを直接予測または検証することができます。 yolo predict model=yolo11n.onnx.使用例は、エクスポート完了後に表示されます。

フォーマットformat 議論モデルメタデータ論争
PyTorch-yolo11n.pt-
TorchScripttorchscriptyolo11n.torchscriptimgsz, optimize, batch
ONNXonnxyolo11n.onnximgsz, half, dynamic, simplify, opset, batch
OpenVINOopenvinoyolo11n_openvino_model/imgsz, half, int8, batch
TensorRTengineyolo11n.engineimgsz, half, dynamic, simplify, workspace, int8, batch
CoreMLcoremlyolo11n.mlpackageimgsz, half, int8, nms, batch
TF SavedModelsaved_modelyolo11n_saved_model/imgsz, keras, int8, batch
TF GraphDefpbyolo11n.pbimgsz, batch
TF ライトtfliteyolo11n.tfliteimgsz, half, int8, batch
TF エッジTPUedgetpuyolo11n_edgetpu.tfliteimgsz
TF.jstfjsyolo11n_web_model/imgsz, half, int8, batch
PaddlePaddlepaddleyolo11n_paddle_model/imgsz, batch
NCNNncnnyolo11n_ncnn_model/imgsz, half, batch

よくあるご質問

How do I export a YOLO11 model to ONNX format?

Exporting a YOLO11 model to ONNX format is straightforward with Ultralytics. It provides both Python and CLI methods for exporting models.

from ultralytics import YOLO

# Load a model
model = YOLO("yolo11n.pt")  # load an official model
model = YOLO("path/to/best.pt")  # load a custom trained model

# Export the model
model.export(format="onnx")
yolo export model=yolo11n.pt format=onnx  # export official model
yolo export model=path/to/best.pt format=onnx  # export custom trained model

For more details on the process, including advanced options like handling different input sizes, refer to the ONNX section.

モデルのエクスポートにTensorRT を使用する利点は何ですか?

Using TensorRT for model export offers significant performance improvements. YOLO11 models exported to TensorRT can achieve up to a 5x GPU speedup, making it ideal for real-time inference applications.

  • 汎用性:特定のハードウェアセットアップにモデルを最適化します。
  • スピード:高度な最適化により、より高速な推論を実現。
  • 互換性: NVIDIA ハードウェアとスムーズに統合。

To learn more about integrating TensorRT, see the TensorRT integration guide.

How do I enable INT8 quantization when exporting my YOLO11 model?

INT8量子化は、特にエッジデバイスにおいて、モデルを圧縮し、推論を高速化する優れた方法です。ここでは、INT8量子化を有効にする方法を説明します:

from ultralytics import YOLO

model = YOLO("yolo11n.pt")  # Load a model
model.export(format="onnx", int8=True)
yolo export model=yolo11n.pt format=onnx int8=True   # export model with INT8 quantization

INT8 quantization can be applied to various formats, such as TensorRT and CoreML. More details can be found in the Export section.

モデルをエクスポートする際に、なぜ動的入力サイズが重要なのですか?

動的入力サイズは、エクスポートされたモデルが様々な画像寸法を扱うことを可能にし、柔軟性を提供し、様々なユースケースに対して処理効率を最適化します。ONNX やTensorRT のような形式にエクスポートする場合、ダイナミック入力サイズを有効にすることで、モデルが異なる入力形状にシームレスに適応できるようになります。

この機能を有効にするには dynamic=True フラグを立てる:

from ultralytics import YOLO

model = YOLO("yolo11n.pt")
model.export(format="onnx", dynamic=True)
yolo export model=yolo11n.pt format=onnx dynamic=True

詳しくは、ダイナミック・インプット・サイズのコンフィギュレーションを参照のこと。

モデルのパフォーマンスを最適化するために考慮すべき重要な輸出論拠とは?

エクスポートの引数を理解し設定することは、モデルのパフォーマンスを最適化するために非常に重要です:

  • format: エクスポートされるモデルのターゲットフォーマット(例. onnx, torchscript, tensorflow).
  • imgsz: モデル入力に必要な画像サイズ(例. 640 または (height, width)).
  • half: FP16量子化が可能になり、モデルサイズが小さくなり、推論が高速化する可能性がある。
  • optimize: モバイルや制約のある環境向けに、特定の最適化を適用する。
  • int8: INT8量子化を可能にし、エッジ展開に非常に有効。

For a detailed list and explanations of all the export arguments, visit the Export Arguments section.

📅 Created 11 months ago ✏️ Updated 20 days ago

コメント