コンテンツへスキップ

Triton 推論サーバーUltralytics YOLOv8

Triton Inference Server(旧称TensorRT Inference Server)は、NVIDIA によって開発されたオープンソースのソフトウェアソリューションである。NVIDIA GPU 向けに最適化されたクラウド推論ソリューションを提供します。Triton は、本番環境における AI モデルの大規模展開を簡素化します。Ultralytics YOLOv8 をTriton Inference Server と統合することで、スケーラブルで高性能な深層学習推論ワークロードを展開することができます。このガイドでは、統合のセットアップとテストの手順を説明します。



見るんだ: NVIDIA Triton Inference Serverを使い始める。

Triton 推論サーバーとは?

Triton Inference Serverは、様々なAIモデルを本番環境で展開するために設計されている。TensorFlow 、PyTorch 、ONNX Runtime、その他多くのディープラーニングや機械学習フレームワークを幅広くサポートしています。主なユースケースは以下の通り:

  • 単一のサーバーインスタンスから複数のモデルを提供する。
  • サーバーを再起動することなく、モデルの動的なロードとアンロードが可能。
  • アンサンブル推論。複数のモデルを一緒に使用して結果を得ることができる。
  • A/Bテストとローリングアップデートのためのモデルのバージョニング。

前提条件

先に進む前に、以下の前提条件が揃っていることを確認してください:

  • あなたのマシンにインストールされているDocker。
  • インストール tritonclient:
    pip install tritonclient[all]
    

YOLOv8 からONNX 形式へのエクスポート

モデルをTriton にデプロイする前に、ONNX フォーマットにエクスポートする必要がある。ONNX (Open Neural Network Exchange)は、異なるディープラーニング・フレームワーク間でモデルを転送できるフォーマットです。を使用する。 export 関数から YOLO クラスである:

from ultralytics import YOLO

# Load a model
model = YOLO("yolov8n.pt")  # load an official model

# 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()
    

Triton 推論サーバーの実行

Docker を使って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:23.09-py3"  # 6.4 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 -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)

上記のステップに従うことで、Ultralytics YOLOv8 モデルをTriton Inference Server 上で効率的にデプロイして実行することができ、ディープラーニングの推論タスクにスケーラブルで高性能なソリューションを提供することができます。何か問題に直面したり、さらに質問がある場合は、 Triton 公式ドキュメントを参照するか、Ultralytics コミュニティにサポートを求めてください。

よくあるご質問

Ultralytics YOLOv8 をNVIDIA Triton 推論サーバーに設定するには?

設定 Ultralytics YOLOv8NVIDIA Triton Inference Serverでは、いくつかの重要なステップがある:

  1. YOLOv8 をONNX フォーマットにエクスポート

    from ultralytics import YOLO
    
    # Load a model
    model = YOLO("yolov8n.pt")  # load an official model
    
    # Export the model to ONNX format
    onnx_file = model.export(format="onnx", dynamic=True)
    
  2. Triton Model Repositoryをセットアップする:

    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:23.09-py3"
    
    subprocess.call(f"docker pull {tag}", shell=True)
    
    container_id = (
        subprocess.check_output(
            f"docker run -d --rm -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)
    

このセットアップにより、YOLOv8 モデルをTriton Inference Server 上で効率的にスケール展開し、高性能なAIモデル推論を行うことができます。

Ultralytics YOLOv8 をNVIDIA Triton Inference Server と一緒に使うと、どんな利点がありますか?

推論サーバーとの統合 Ultralytics YOLOv8NVIDIA Triton Inference Serverとの統合にはいくつかの利点がある:

  • スケーラブルなAI推論:Triton は、単一のサーバー・インスタンスから複数のモデルを提供することができ、モデルの動的なロードとアンロードをサポートするため、多様なAIワークロードに対して高いスケーラビリティを実現します。
  • 高性能:NVIDIA GPU用に最適化されたTriton Inference Serverは、高速推論オペレーションを保証し、物体検出などのリアルタイムアプリケーションに最適です。
  • アンサンブルとモデルのバージョニング:Triton のアンサンブル・モードは、複数のモデルを組み合わせて結果を改善することができ、モデルのバージョニングはA/Bテストとローリングアップデートをサポートします。

Triton でYOLOv8 をセットアップして実行するための詳細な手順については、セットアップガイドを参照してください。

Triton Inference Server を使用する前に、YOLOv8 モデルをONNX フォーマットにエクスポートする必要があるのはなぜですか?

ONNX (Open Neural Network Exchange) フォーマットを使用することで、モデルを Inference Server にデプロイすることができます。 Ultralytics YOLOv8 NVIDIA Triton Inference Server にデプロイする前に、モデルに (Open Neural Network Exchange) フォーマットを使用すると、いくつかの重要な利点があります:

  • 相互運用性:ONNX フォーマットは、異なるディープラーニングフレームワーク(PyTorch やTensorFlow など)間の転送をサポートし、より幅広い互換性を確保する。
  • 最適化:Triton を含む多くの展開環境は、ONNX のために最適化され、より高速な推論と優れたパフォーマンスを可能にする。
  • 導入の容易さ:ONNX は、フレームワークやプラットフォーム間で幅広くサポートされているため、さまざまなオペレーティングシステムやハードウェア構成での導入プロセスが簡素化される。

モデルをエクスポートするには

from ultralytics import YOLO

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

エクスポート・ガイドの手順に従って、プロセスを完了することができます。

Triton Inference Server上で、Ultralytics YOLOv8 モデルを使って推論を行うことはできますか?

はい。 Ultralytics YOLOv8NVIDIA Triton モデルを使用して 推論を実行することができます。モデルがTriton モデルリポジトリにセットアップされ、サーバーが起動していれば、以下のようにモデルをロードして推論を実行することができます:

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")

YOLOv8 を使用したTriton サーバーのセットアップと実行に関する詳細なガイドについては、 triton 推論サーバーの実行セクションを参照してください。

Ultralytics YOLOv8 は、TensorFlow やPyTorch の展開モデルと比較してどうですか?

Ultralytics YOLOv8は、TensorFlow やPyTorch の展開モデルと比較して、いくつかのユニークな利点を提供している:

  • リアルタイム性能:リアルタイムの物体検出タスク用に最適化されたYOLOv8 は、最先端の精度とスピードを提供し、ライブビデオ解析を必要とするアプリケーションに最適です。
  • 使いやすさ:YOLOv8 はTriton Inference Server とシームレスに統合され、多様なエクスポートフォーマット (ONNX,TensorRT,CoreML) をサポートしているため、さまざまな展開シナリオに柔軟に対応できます。
  • 高度な機能:YOLOv8 には、動的モデル・ローディング、モデル・バージョニング、アンサンブル推論などの機能が含まれており、これらはスケーラブルで信頼性の高いAI導入に不可欠です。

詳細については、モデル展開ガイドの展開オプションを比較してください。



作成日:2023-11-12 更新日:2024-07-05
作成者:glenn-jocher(10)

コメント