Link to this sectionTriton Inference Server と Ultralytics YOLO26#
Triton Inference Server(旧称:TensorRT Inference Server)は、NVIDIA が開発したオープンソースのソフトウェアソリューションです。これは NVIDIA GPU に最適化されたクラウド推論ソリューションを提供します。Triton は、本番環境における AI モデルのスケーラブルなデプロイを簡素化します。Ultralytics YOLO26 を Triton Inference Server と統合することで、スケーラブルで高性能な deep learning 推論ワークロードをデプロイできます。本ガイドでは、この統合をセットアップおよびテストする手順を説明します。
Watch: Getting Started with NVIDIA Triton Inference Server.
Link to this sectionTriton Inference Server とは?#
Triton Inference Server is designed to deploy a variety of AI models in production. It supports a wide range of deep learning and machine learning frameworks, including PyTorch, TensorFlow, ONNX, OpenVINO, TensorRT and many others. Its primary use cases are:
- 単一のサーバーインスタンスから複数のモデルを提供
- サーバーを再起動せずにモデルを動的に読み込み、アンロードする機能
- アンサンブル推論(複数のモデルを組み合わせて結果を得ることが可能)
- A/B テストやローリングアップデートのためのモデルバージョン管理
Link to this sectionTriton Inference Server の主な利点#
Triton Inference Server を Ultralytics YOLO26 と併用することで、いくつかの利点が得られます。
- 自動バッチ処理: 複数の AI リクエストを処理前にグループ化することで、レイテンシを削減し、推論速度を向上させます。
- Kubernetes 統合: クラウドネイティブな設計により、Kubernetes とシームレスに連携し、AI アプリケーションの管理とスケーリングを可能にします。
- ハードウェア固有の最適化: NVIDIA GPU の性能を最大限に引き出します。
- フレームワークの柔軟性: PyTorch、TensorFlow、ONNX、OpenVINO、TensorRT を含む複数の AI フレームワークをサポートしています。
- オープンソースでカスタマイズ可能: 特定のニーズに合わせて変更可能であり、さまざまな AI アプリケーションに対して柔軟性を提供します。
Link to this section前提条件#
先に進む前に、以下の前提条件が満たされていることを確認してください。
- マシンに Docker または Podman がインストールされていること
ultralyticsをインストールする:pip install ultralyticstritonclientをインストールする:pip install tritonclient[all]
Link to this sectionTriton Inference Server のセットアップ#
このフルセットアップブロックを実行して Ultralytics YOLO26 を ONNX にエクスポートし、Triton モデルリポジトリを構築して、Triton Inference Server を起動します。
スクリプト内の runtime スイッチを使用して、使用するコンテナエンジンを選択します。
- Docker の場合は
runtime = "docker"を設定します。 - Podman の場合は
runtime = "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"
}
}
# Enable TensorRT acceleration (requires a GPU and TensorRT-enabled Triton; remove this block for CPU-only serving)
# The 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)Link to this section推論の実行#
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")コンテナをクリーンアップします:
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)Link to this sectionTensorRT 最適化(オプション)#
さらにパフォーマンスを向上させるには、Triton Inference Server で TensorRT を使用できます。TensorRT は NVIDIA GPU 専用に構築された高性能な deep learning オプティマイザであり、推論速度を大幅に向上させることができます。
Triton で TensorRT を使用する主な利点は以下の通りです。
- 最適化されていないモデルと比較して、推論速度が最大 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コミュニティにお問い合わせください。
Link to this sectionよくある質問 (FAQ)#
Link to this sectionUltralytics YOLO26 を NVIDIA Triton Inference Server にセットアップする方法は?#
Ultralytics YOLO26 を NVIDIA Triton Inference Server にセットアップするには、いくつかの重要なステップが必要です。
-
YOLO26 を ONNX 形式にエクスポートする:
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 モデルリポジトリをセットアップする:
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() -
Triton 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 YOLO26 モデルを Triton Inference Server 上で大規模に効率よくデプロイし、高性能な AI モデル推論を実現できます。
Link to this sectionUltralytics YOLO26 を NVIDIA Triton Inference Server と併用することの利点は何ですか?#
Ultralytics YOLO26 を NVIDIA Triton Inference Server と統合すると、いくつかの利点があります。
- スケーラブルな AI 推論: Triton は単一のサーバーインスタンスから複数のモデルを提供でき、モデルの動的な読み込みとアンロードをサポートしているため、多様な AI ワークロードに対して非常にスケーラブルです。
- 高性能: NVIDIA GPU に最適化されており、Triton Inference Server は高速な推論オペレーションを実現し、object detection などのリアルタイムアプリケーションに最適です。
- アンサンブルとモデルバージョン管理: Triton のアンサンブルモードでは複数のモデルを組み合わせて結果を向上させることができ、モデルバージョン管理機能は A/B テストやローリングアップデートをサポートします。
- 自動バッチ処理: Triton は複数の推論リクエストを自動的にグループ化し、スループットを大幅に向上させるとともにレイテンシを削減します。
- デプロイの簡素化: システム全体を刷新することなく AI ワークフローを段階的に最適化できるため、効率的なスケーリングが容易になります。
TritonでUltralytics YOLO26をセットアップして実行するための詳細な手順については、Triton Inference Serverのセットアップおよび推論の実行を参照してください。
Link to this sectionTriton Inference Server を使用する前に、YOLO26 モデルを ONNX 形式にエクスポートする必要があるのはなぜですか?#
Ultralytics YOLO26 モデルを NVIDIA Triton Inference Server にデプロイする前に ONNX (Open Neural Network Exchange) 形式を使用することには、いくつかの重要な利点があります。
- 相互運用性: ONNX 形式は異なる deep learning フレームワーク(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統合ガイドの手順に従ってプロセスを完了できます。
Link to this sectionTriton Inference Server 上で Ultralytics YOLO26 モデルを使用して推論を実行できますか?#
Yes, you can run inference using the Ultralytics YOLO26 model on NVIDIA Triton Inference Server. Once your model is set up in the Triton Model Repository and the server is running, you can load and run inference on your model as follows:
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 の最適化を活用できます。
Link to this sectionUltralytics YOLO26 は、デプロイメントにおいて TensorFlow や PyTorch モデルと比べてどうですか?#
Ultralytics YOLO26 は、デプロイメントにおいて TensorFlow や PyTorch モデルと比較して、いくつかのユニークな利点を提供します。
- リアルタイムパフォーマンス: リアルタイムの物体検出タスク向けに最適化されており、Ultralytics YOLO26 は最先端の accuracy とスピードを提供し、ライブビデオ解析が必要なアプリケーションに最適です。
- 使いやすさ: Ultralytics YOLO26 は Triton Inference Server とシームレスに統合され、多様なエクスポート形式(ONNX、TensorRT)をサポートしているため、さまざまなデプロイシナリオに柔軟に対応できます。
- 高度な機能: Ultralytics YOLO26 には、動的モデル読み込み、モデルバージョン管理、アンサンブル推論などの、スケーラブルで信頼性の高い AI デプロイに不可欠な機能が含まれています。
- 簡素化された API: Ultralytics API は、さまざまなデプロイターゲット間で一貫したインターフェースを提供し、学習コストと開発時間を削減します。
- エッジ最適化: Ultralytics YOLO26 モデルはエッジデプロイを念頭に置いて設計されており、リソースが制限されたデバイス上でも優れたパフォーマンスを発揮します。
詳細については、モデルエクスポートガイド でデプロイメントオプションを比較してください。