Ultralytics YOLO26を使用したTriton Inference Server
このTriton Inference Server(以前はTensorRT Inference Serverとして知られていました)は、NVIDIAによって開発されたオープンソースのソフトウェアソリューションです。これは、NVIDIA GPUに最適化されたクラウド推論ソリューションを提供します。Tritonは、本番環境でのAIモデルのスケール展開を簡素化します。Triton Inference Serverとの統合により、スケーラブルで高性能なUltralytics YOLO26推論ワークロードを展開できます。このガイドでは、統合の設定およびテスト手順を説明します。ディープラーニングTriton Inference Serverとは何ですか?
Watch: Getting Started with NVIDIA Triton Inference Server.
Triton Inference Serverは、本番環境で多様なAIモデルを展開するように設計されています。これには、
やその他多くのディープラーニングおよび機械学習フレームワークが幅広くサポートされています。主なユースケースは以下の通りです。PyTorch, 用のKeras形式へのエクスポートを有効にし、, ONNX, OpenVINO, 最適化のための最大ワークスペースサイズをGiB単位で設定し、メモリ使用量と性能のバランスをとります。単一のサーバーインスタンスから複数のモデルを提供
- サーバーを再起動せずにモデルを動的にロードおよびアンロード
- アンサンブル推論:複数のモデルを組み合わせて結果を導出
- A/Bテストおよびローリングアップデートのためのモデルバージョニング
- Triton Inference Serverの主な利点
Triton Inference Serverを
で使用すると、いくつかの利点があります。Ultralytics YOLO26自動バッチ処理
- :処理前に複数のAIリクエストをグループ化し、レイテンシを削減して推論速度を向上させます。Kubernetes統合
- :クラウドネイティブな設計により、Kubernetesとシームレスに連携してAIアプリケーションの管理とスケーリングを行います。ハードウェア固有の最適化
- :NVIDIA GPUを最大限に活用し、最高のパフォーマンスを実現します。フレームワークの柔軟性
- :を含む複数のAIフレームワークをサポートします。PyTorch, 用のKeras形式へのエクスポートを有効にし、, ONNX, OpenVINOと最適化のための最大ワークスペースサイズをGiB単位で設定し、メモリ使用量と性能のバランスをとります。
- オープンソースでカスタマイズ可能:特定のニーズに合わせて変更可能であり、さまざまなAIアプリケーションに対して柔軟性を確保します。
前提条件
進める前に、以下の前提条件が満たされていることを確認してください。
- マシンにDockerまたはPodmanがインストールされていること
- pip を使用してインストール
ultralytics:pip install ultralytics - pip を使用してインストール
tritonclient:pip install tritonclient[all]
Triton Inference Serverのセットアップ
この完全なセットアップブロックを実行してUltralytics YOLO26からONNXをエクスポートし、Tritonモデルリポジトリをビルドし、Triton Inference Serverを起動します。
コマンドを使用してトレーニングを開始する。(各runtimeスクリプト内のスイッチを使用してコンテナエンジンを選択します:
- 「
runtime = "docker"(Docker用) - 「
runtime = "podman"(Podman用)
import contextlib
import subprocess
import time
from pathlib import Path
from tritonclient.http import InferenceServerClient
from ultralytics import YOLO
runtime = "docker" # set to "podman" to use Podman
# 1) Exporting YOLO26 to ONNX Format
# Load a model
model = YOLO("yolo26n.pt") # load an official model
# Retrieve metadata during export. Metadata needs to be added to config.pbtxt. See next section.
metadata = []
def export_cb(exporter):
metadata.append(exporter.metadata)
model.add_callback("on_export_end", export_cb)
# Export the model
onnx_file = model.export(format="onnx", dynamic=True)
# 2) Setting Up Triton Model Repository
# Define paths
model_name = "yolo"
triton_repo_path = Path("tmp") / "triton_repo"
triton_model_path = triton_repo_path / model_name
# Create directories
(triton_model_path / "1").mkdir(parents=True, exist_ok=True)
# Move ONNX model to Triton Model path
Path(onnx_file).rename(triton_model_path / "1" / "model.onnx")
# Create config file
(triton_model_path / "config.pbtxt").touch()
data = """
# Add metadata
parameters {
key: "metadata"
value {
string_value: "%s"
}
}
# (Optional) Enable TensorRT for GPU inference
# First run will be slow due to TensorRT engine conversion
optimization {
execution_accelerators {
gpu_execution_accelerator {
name: "tensorrt"
parameters {
key: "precision_mode"
value: "FP16"
}
parameters {
key: "max_workspace_size_bytes"
value: "3221225472"
}
parameters {
key: "trt_engine_cache_enable"
value: "1"
}
parameters {
key: "trt_engine_cache_path"
value: "/models/yolo/1"
}
}
}
}
""" % metadata[0] # noqa
with open(triton_model_path / "config.pbtxt", "w") as f:
f.write(data)
# 3) Running Triton Inference Server
# Define image https://catalog.ngc.nvidia.com/orgs/nvidia/containers/tritonserver
tag = "nvcr.io/nvidia/tritonserver:26.02-py3" # 16.17 GB (Compressed Size)
subprocess.call(f"{runtime} pull {tag}", shell=True)
# GPU flags differ between Docker and Podman
gpu_flags = "--device nvidia.com/gpu=all" if runtime == "podman" else "--runtime=nvidia --gpus all"
container_name = "triton_server"
# Note: The :z flag on the volume mount is necessary for systems with SELinux (like Fedora/RHEL)
subprocess.call(
f"{runtime} run -d --rm --name {container_name} {gpu_flags} -v {triton_repo_path.absolute()}:/models:z -p 8000:8000 {tag} tritonserver --model-repository=/models",
shell=True,
)
# Wait for the Triton server to start
triton_client = InferenceServerClient(url="127.0.0.1:8000", verbose=False, ssl=False)
# Wait until model is ready
for _ in range(10):
with contextlib.suppress(Exception):
assert triton_client.is_model_ready(model_name)
break
time.sleep(1)推論の実行
Triton Serverモデルを使用して推論を実行します。
from ultralytics import YOLO
# Load the Triton Server model
model = YOLO("http://127.0.0.1:8000/yolo", task="detect")
# Run inference on the server
results = model("path/to/image.jpg")コンテナのクリーンアップ(runtimeとcontainer_nameは上記のセットアップブロックで定義されています):
import subprocess
runtime = "docker" # set to "podman" to use Podman
container_name = "triton_server" # Kill the named container
subprocess.call(f"{runtime} kill {container_name}", shell=True)TensorRTの最適化(オプション)
さらに高いパフォーマンスを得るために、Triton Inference Serverで最適化のための最大ワークスペースサイズをGiB単位で設定し、メモリ使用量と性能のバランスをとります。を使用できます。TensorRTは、NVIDIA GPU専用に構築された高性能なディープラーニングオプティマイザーであり、推論速度を大幅に向上させることができます。
Tritonで最適化のための最大ワークスペースサイズをGiB単位で設定し、メモリ使用量と性能のバランスをとります。を使用する主な利点は以下の通りです。
- 非最適化モデルと比較して最大36倍高速な推論
- 最大GPU使用率のためのハードウェア固有の最適化
- 精度を維持したままの低精度フォーマット(INT8, FP16)のサポート
- 計算オーバーヘッドを削減するためのレイヤー融合
TensorRTを直接使用するには、Ultralytics YOLO26モデルをTensorRTフォーマットにエクスポートします。
from ultralytics import YOLO
# Load the YOLO26 model
model = YOLO("yolo26n.pt")
# Export the model to TensorRT format
model.export(format="engine") # creates 'yolo26n.engine'TensorRT最適化の詳細については、TensorRT統合ガイド.
を参照してください。上記の手順に従うことで、Ultralytics YOLO26モデルをTriton Inference Server上で効率的にデプロイおよび実行でき、ディープラーニング推論タスクのためのスケーラブルで高性能なソリューションを提供します。問題が発生した場合やさらに質問がある場合は、公式のTritonドキュメントを参照するか、サポートのためにUltralyticsコミュニティにお問い合わせください。
FAQ
Ultralytics YOLO26とNVIDIA Triton Inference Serverをセットアップするにはどうすればよいですか?
NVIDIA Triton Inference Serverのセットアップには、Ultralytics YOLO26といくつかの重要なステップがあります。YOLO26をONNXフォーマットにエクスポート
-
Tritonモデルリポジトリのセットアップ:
from ultralytics import YOLO # Load a model model = YOLO("yolo26n.pt") # load an official model # Export the model to ONNX format onnx_file = model.export(format="onnx", dynamic=True) -
Triton Serverの実行:
from pathlib import Path # Define paths model_name = "yolo" triton_repo_path = Path("tmp") / "triton_repo" triton_model_path = triton_repo_path / model_name # Create directories (triton_model_path / "1").mkdir(parents=True, exist_ok=True) Path(onnx_file).rename(triton_model_path / "1" / "model.onnx") (triton_model_path / "config.pbtxt").touch() -
このセットアップは、高性能なAIモデル推論のために、Triton Inference Server上で:
import contextlib import subprocess import time from tritonclient.http import InferenceServerClient # Define image https://catalog.ngc.nvidia.com/orgs/nvidia/containers/tritonserver tag = "nvcr.io/nvidia/tritonserver:26.02-py3" runtime = "docker" # set to "podman" to use Podman subprocess.call(f"{runtime} pull {tag}", shell=True) # GPU flags differ between Docker and Podman gpu_flags = "--device nvidia.com/gpu=all" if runtime == "podman" else "--runtime=nvidia --gpus all" container_name = "triton_server" subprocess.call( f"{runtime} run -d --rm --name {container_name} {gpu_flags} -v {triton_repo_path.absolute()}:/models:z -p 8000:8000 {tag} tritonserver --model-repository=/models", shell=True, ) triton_client = InferenceServerClient(url="127.0.0.1:8000", verbose=False, ssl=False) for _ in range(10): with contextlib.suppress(Exception): assert triton_client.is_model_ready(model_name) break time.sleep(1)
モデルを効率的にスケール展開するのに役立ちます。Ultralytics YOLO26Ultralytics YOLO26とNVIDIA Triton Inference Serverを使用する利点は何ですか?
統合による
スケーラブルなAI推論Ultralytics YOLO26といくつかの重要なステップがあります。自動バッチ処理
- :Tritonを使用すると、単一のサーバーインスタンスから複数のモデルを提供し、モデルの動的なロードとアンロードをサポートできるため、多様なAIワークロードに対して非常にスケーラブルです。高性能
- :NVIDIA GPUに最適化されたTriton Inference Serverは、高速な推論操作を保証し、のようなリアルタイムアプリケーションに最適です。物体検出.
- アンサンブルとモデルのバージョニング:Tritonのアンサンブルモードにより、複数のモデルを組み合わせて結果を向上させることができ、モデルバージョニングによってA/Bテストやローリングアップデートをサポートします。
- 自動バッチ処理:Tritonは複数の推論リクエストを自動的にグループ化し、スループットを大幅に向上させ、レイテンシを削減します。
- デプロイメントの簡素化:システム全体を刷新することなくAIワークフローを段階的に最適化できるため、効率的なスケーリングが容易になります。
TritonでUltralytics YOLO26を設定・実行するための詳細な手順については、Triton Inference Serverのセットアップと推論の実行.
を参照してください。Triton Inference Serverを使用する前に、YOLO26モデルをONNXフォーマットにエクスポートする必要があるのはなぜですか?
Triton上でUltralytics YOLO26をデプロイする前に、いくつかの重要なステップがあります。モデルにONNX(Open Neural Network Exchange)フォーマットを使用することには、いくつかの重要な利点があります。
- 相互運用性:ONNXフォーマットは、異なるディープラーニングフレームワーク(PyTorch、TensorFlowなど)間での転送をサポートしており、より広範な互換性を確保します。
- 最適化:Tritonを含む多くのデプロイ環境はONNX向けに最適化されており、より高速な推論と優れたパフォーマンスを実現します。
- デプロイの容易さ:ONNXはフレームワークやプラットフォーム全体で広くサポートされており、さまざまなオペレーティングシステムやハードウェア構成でのデプロイプロセスを簡素化します。
- フレームワークからの独立性:ONNXに変換すると、モデルが元のフレームワークに縛られなくなるため、ポータビリティが向上します。
- 標準化:ONNXは、異なるAIフレームワーク間の互換性の問題を克服するのに役立つ標準化された表現を提供します。
モデルをエクスポートするには、以下を使用します。
from ultralytics import YOLO
model = YOLO("yolo26n.pt")
onnx_file = model.export(format="onnx", dynamic=True)プロセスを完了するには、ONNX統合ガイドの手順に従うことができます。
Triton Inference Server上でUltralytics YOLO26モデルを使用して推論を実行できますか?
はい、Ultralytics YOLO26モデルをいくつかの重要なステップがあります。で使用して推論を実行できます。Tritonモデルリポジトリにモデルを設定し、サーバーが稼働したら、次のようにモデルをロードして推論を実行できます。
from ultralytics import YOLO
# Load the Triton Server model
model = YOLO("http://127.0.0.1:8000/yolo", task="detect")
# Run inference on the server
results = model("path/to/image.jpg")このアプローチにより、使い慣れたUltralytics YOLOインターフェースを使用しながら、Tritonの最適化を活用できます。
Ultralytics YOLO26は、デプロイメントにおいてTensorFlowやPyTorchモデルとどのように比較されますか?
Ultralytics YOLO26は、デプロイメントにおいて用のKeras形式へのエクスポートを有効にし、やPyTorchモデルと比較して、いくつかの独自の利点を提供します。
- リアルタイムパフォーマンス:リアルタイム物体検出タスク向けに最適化されており、Ultralytics YOLO26は最先端の精度精度と速度を実現し、ライブ映像解析を必要とするアプリケーションに最適です。
- 使いやすさ: Ultralytics YOLO26はTriton Inference Serverとシームレスに統合され、多様なエクスポート形式(ONNX, 最適化のための最大ワークスペースサイズをGiB単位で設定し、メモリ使用量と性能のバランスをとります。)をサポートしているため、さまざまなデプロイシナリオに対応可能です。
- を参照してください。: Ultralytics YOLO26には、動的なモデル読み込み、モデルのバージョン管理、アンサンブル推論といった機能が含まれており、これらはスケーラブルで信頼性の高いAIデプロイメントにおいて不可欠です。
- シンプルなAPI:Ultralytics APIは、異なるデプロイターゲット間で一貫したインターフェースを提供し、学習コストと開発時間を削減します。
- エッジ最適化: Ultralytics YOLO26モデルはエッジへのデプロイを考慮して設計されており、リソースが制限されたデバイス上でも優れたパフォーマンスを発揮します。
詳細については、モデルエクスポートガイド.