コンテンツにスキップ

Ultralytics YOLO11 を使用した Triton Inference Server

<a href="https://developer.nvidia.com/dynamo">Triton Inference Server(以前はTensorRT Inference Serverとして知られていました)は、NVIDIAによって開発されたオープンソースソフトウェアソリューションです。NVIDIA GPU用に最適化されたクラウド推論ソリューションを提供します。Tritonは、本番環境でのAIモデルの大規模なデプロイを簡素化します。Ultralytics YOLO11をTriton Inference Serverと統合することで、スケーラブルで高性能な<a href="https://www.ultralytics.com/glossary/deep-learning-dl">深層学習推論ワークロードをデプロイできます。このガイドでは、統合を設定およびテストする手順について説明します。



見る: NVIDIA Triton Inference Serverの利用開始。

Triton Inference Serverとは何ですか?

Triton Inference Serverは、さまざまなAIモデルを本番環境にデプロイするために設計されています。TensorFlow、PyTorch、ONNX Runtimeをはじめとする、幅広い深層学習および機械学習フレームワークをサポートしています。主なユースケースは以下のとおりです。

  • 単一のサーバーインスタンスから複数のモデルを提供
  • サーバーを再起動せずにモデルを動的にロードおよびアンロード
  • アンサンブル推論。複数のモデルを組み合わせて使用​​して結果を達成できるようにします
  • A/Bテストとローリングアップデートのためのモデルのバージョン管理

Triton Inference Serverの主な利点

Ultralytics YOLO11でTriton Inference Serverを使用すると、いくつかの利点があります。

  • 自動バッチ処理: 複数のAIリクエストをまとめて処理することで、レイテンシーを削減し、推論速度を向上させます。
  • Kubernetes統合: クラウドネイティブな設計により、AIアプリケーションの管理とスケーリングのためにKubernetesとシームレスに連携します。
  • ハードウェア固有の最適化: NVIDIA GPU を最大限に活用して、最高のパフォーマンスを実現します。
  • フレームワークの柔軟性: TensorFlow、PyTorch、ONNX、TensorRTを含む複数のAIフレームワークをサポートします
  • オープンソースでカスタマイズ可能: 特定のニーズに合わせて変更でき、さまざまなAIアプリケーションに柔軟に対応できます。

前提条件

先に進む前に、以下の前提条件を満たしていることを確認してください。

  • マシンにDockerがインストールされていること
  • インストール tritonclient:
    pip install tritonclient[all]
    

YOLO11をONNX形式へエクスポート

Tritonにモデルをデプロイする前に、ONNX形式にエクスポートする必要があります。ONNX(Open Neural Network Exchange)は、異なる深層学習フレームワーク間でモデルを転送できる形式です。以下のコマンドを使用します。 export の機能: YOLO クラス:

from ultralytics import YOLO

# Load a model
model = YOLO("yolo11n.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)

Triton モデルリポジトリのセットアップ

Tritonモデルリポジトリは、Tritonがモデルにアクセスしてロードできるストレージの場所です。

  1. 必要なディレクトリ構造を作成します。

    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)
    
  2. エクスポートされたONNXモデルをTritonリポジトリに移動します:

    from pathlib import Path
    
    # 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)
    

Triton Inference Serverの実行

Docker を使用して Triton 推論サーバーを実行:

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:24.09-py3"  # 8.57 GB

# Pull the image
subprocess.call(f"docker pull {tag}", shell=True)

# Run the Triton server and capture the container ID
container_id = (
    subprocess.check_output(
        f"docker run -d --rm --gpus 0 -v {triton_repo_path}:/models -p 8000:8000 {tag} tritonserver --model-repository=/models",
        shell=True,
    )
    .decode("utf-8")
    .strip()
)

# Wait for the Triton server to start
triton_client = InferenceServerClient(url="localhost: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://localhost:8000/yolo", task="detect")

# Run inference on the server
results = model("path/to/image.jpg")

コンテナのクリーンアップ:

# Kill and remove the container at the end of the test
subprocess.call(f"docker kill {container_id}", shell=True)

TensorRTの最適化(オプション)

さらに高いパフォーマンスを得るには、TensorRTと Triton Inference Server を組み合わせて使用できます。TensorRT は、NVIDIA GPU 向けに特別に構築された高性能な深層学習オプティマイザであり、推論速度を大幅に向上させることができます。

TensorRTをTritonで使用する主な利点は次のとおりです。

  • 最適化されていないモデルと比較して最大36倍高速な推論
  • GPUを最大限に活用するためのハードウェア固有の最適化
  • 精度を維持しながら、低精度フォーマット(INT8、FP16)をサポート
  • 計算オーバーヘッドを削減するためのレイヤー融合

TensorRTを直接使用するには、YOLO11モデルをTensorRT形式にエクスポートします。

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'

TensorRT の最適化に関する詳細については、TensorRT 統合ガイドをご覧ください。


上記の手順に従うことで、Ultralytics YOLO11モデルをTriton Inference Serverに効率的にデプロイして実行し、深層学習推論タスク向けのスケーラブルで高性能なソリューションを提供できます。問題が発生した場合や、さらに質問がある場合は、Tritonの公式ドキュメントを参照するか、Ultralyticsコミュニティに連絡してサポートを受けてください。

よくある質問

NVIDIA Triton Inference Server で Ultralytics YOLO11 をセットアップするにはどうすればよいですか?

Ultralytics YOLO11NVIDIA Triton Inference Server と共にセットアップするには、いくつかの重要なステップがあります。

  1. YOLO11をONNX形式でエクスポート:

    from ultralytics import YOLO
    
    # Load a model
    model = YOLO("yolo11n.pt")  # load an official model
    
    # Export the model to ONNX format
    onnx_file = model.export(format="onnx", dynamic=True)
    
  2. 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()
    
  3. Tritonサーバーの実行:

    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:24.09-py3"
    
    subprocess.call(f"docker pull {tag}", shell=True)
    
    container_id = (
        subprocess.check_output(
            f"docker run -d --rm --gpus 0 -v {triton_repo_path}:/models -p 8000:8000 {tag} tritonserver --model-repository=/models",
            shell=True,
        )
        .decode("utf-8")
        .strip()
    )
    
    triton_client = InferenceServerClient(url="localhost: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)
    

この設定は、高性能AIモデル推論のために、Triton Inference ServerでYOLO11モデルを大規模に効率的にデプロイするのに役立ちます。

Ultralytics YOLO11をNVIDIA Triton Inference Serverで使用すると、どのようなメリットがありますか?

Ultralytics YOLO11とNVIDIA Triton Inference Serverを統合すると、いくつかの利点があります。

  • スケーラブルなAI推論: Tritonを使用すると、単一のサーバーインスタンスから複数のモデルを提供でき、動的なモデルのロードとアンロードをサポートするため、多様なAIワークロードに対して高いスケーラビリティを発揮します。
  • ハイパフォーマンス: NVIDIA GPU向けに最適化されたTriton Inference Serverは、高速な推論処理を保証し、物体検出などのリアルタイムアプリケーションに最適です。
  • アンサンブルとモデルのバージョニング: Tritonのアンサンブルモードを使用すると、複数のモデルを組み合わせて結果を改善でき、モデルのバージョニングはA/Bテストとローリングアップデートをサポートします。
  • 自動バッチ処理: Tritonは、複数の推論リクエストを自動的にグループ化し、スループットを大幅に向上させ、レイテンシーを削減します。
  • デプロイメントの簡素化: システム全体を刷新することなく、AIワークフローを段階的に最適化できるため、効率的な拡張が容易になります。

TritonでYOLO11を設定および実行する方法の詳細な手順については、セットアップガイドを参照してください。

Triton Inference Serverを使用する前に、YOLO11モデルをONNX形式にエクスポートすべきなのはなぜですか?

NVIDIA Triton Inference ServerにUltralytics YOLO11モデルをデプロイする前に、ONNX(Open Neural Network Exchange)形式を使用すると、いくつかの重要な利点があります。

  • 相互運用性:ONNX形式は、異なる深層学習フレームワーク(PyTorch、TensorFlowなど)間の転送をサポートし、より広範な互換性を保証します。
  • 最適化: Tritonを含む多くのデプロイ環境はONNX向けに最適化されており、より高速な推論とより優れたパフォーマンスを可能にします。
  • デプロイの容易さ: ONNXは、フレームワークやプラットフォーム間で広くサポートされており、さまざまなオペレーティングシステムやハードウェア構成でのデプロイプロセスを簡素化します。
  • フレームワークからの独立性: ONNXに変換されると、モデルは元のフレームワークに縛られなくなり、移植性が向上します。
  • 標準化: ONNXは、異なるAIフレームワーク間の互換性の問題を克服するのに役立つ標準化された表現を提供します。

モデルをエクスポートするには、以下を使用します。

from ultralytics import YOLO

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

プロセスを完了するには、ONNX統合ガイドの手順に従ってください。

Triton Inference Server上でUltralytics YOLO11モデルを使用して推論を実行できますか?

はい、NVIDIA Triton Inference ServerでUltralytics YOLO11モデルを使用して推論を実行できます。モデルがTriton Model Repositoryに設定され、サーバーが実行されると、次のようにモデルをロードして推論を実行できます。

from ultralytics import YOLO

# Load the Triton Server model
model = YOLO("http://localhost:8000/yolo", task="detect")

# Run inference on the server
results = model("path/to/image.jpg")

このアプローチを使用すると、使い慣れたUltralytics YOLOインターフェイスを使用しながら、Tritonの最適化を活用できます。YOLO11でTriton Serverをセットアップして実行する方法の詳細なガイドについては、Triton推論サーバーの実行セクションを参照してください。

Ultralytics YOLO11は、デプロイメントにおいてTensorFlowやPyTorchのモデルと比べてどうですか?

Ultralytics YOLO11は、デプロイメントに関して、TensorFlowおよびPyTorchモデルと比較していくつかの独自の利点を提供します。

  • リアルタイム性能: リアルタイム物体検出タスクに最適化されたYOLO11は、最先端の精度と速度を提供し、ライブビデオ分析を必要とするアプリケーションに最適です。
  • 使いやすさ: YOLO11 は Triton Inference Server とシームレスに統合され、多様なエクスポート形式 (ONNX、TensorRT、CoreML) をサポートしているため、さまざまなデプロイシナリオに柔軟に対応できます。
  • 高度な機能: YOLO11には、動的なモデルローディング、モデルのバージョン管理、アンサンブル推論などの機能が含まれており、これらはスケーラブルで信頼性の高いAIデプロイメントに不可欠です。
  • APIの簡素化: Ultralytics APIは、さまざまなデプロイメントターゲットにわたって一貫したインターフェースを提供し、学習コストと開発時間を削減します。
  • Edge Optimization: YOLO11モデルはエッジ実装を念頭に置いて設計されており、リソース制約のあるデバイスでも優れたパフォーマンスを提供します。

詳細については、モデルエクスポートガイドでデプロイメントオプションを比較してください。



📅 1年前に作成 ✏️ 5ヶ月前に更新

コメント