コンテンツへスキップ

Triton Inference Server with Ultralytics YOLO11

The Triton Inference Server (formerly known as TensorRT Inference Server) is an open-source software solution developed by NVIDIA. It provides a cloud inference solution optimized for NVIDIA GPUs. Triton simplifies the deployment of AI models at scale in production. Integrating Ultralytics YOLO11 with Triton Inference Server allows you to deploy scalable, high-performance deep learning inference workloads. This guide provides steps to set up and test the integration.



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

Triton 推論サーバーとは?

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 TensorFlow, PyTorch, ONNX Runtime, and many others. Its primary use cases are:

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

前提条件

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

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

Exporting YOLO11 to ONNX Format

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

from ultralytics import YOLO

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

By following the above steps, you can deploy and run Ultralytics YOLO11 models efficiently on Triton Inference Server, providing a scalable and high-performance solution for deep learning inference tasks. If you face any issues or have further queries, refer to the official Triton documentation or reach out to the Ultralytics community for support.

よくあるご質問

How do I set up Ultralytics YOLO11 with NVIDIA Triton Inference Server?

Setting up Ultralytics YOLO11 with NVIDIA Triton Inference Server involves a few key steps:

  1. Export YOLO11 to ONNX format:

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

This setup can help you efficiently deploy YOLO11 models at scale on Triton Inference Server for high-performance AI model inference.

What benefits does using Ultralytics YOLO11 with NVIDIA Triton Inference Server offer?

Integrating Ultralytics YOLO11 with NVIDIA Triton Inference Server provides several advantages:

  • スケーラブルなAI推論:Triton は、単一のサーバー・インスタンスから複数のモデルを提供することができ、モデルの動的なロードとアンロードをサポートするため、多様なAIワークロードに対して高いスケーラビリティを実現します。
  • High Performance: Optimized for NVIDIA GPUs, Triton Inference Server ensures high-speed inference operations, perfect for real-time applications such as object detection.
  • アンサンブルとモデルのバージョニング:Triton のアンサンブル・モードは、複数のモデルを組み合わせて結果を改善することができ、モデルのバージョニングはA/Bテストとローリングアップデートをサポートします。

For detailed instructions on setting up and running YOLO11 with Triton, you can refer to the setup guide.

Why should I export my YOLO11 model to ONNX format before using Triton Inference Server?

Using ONNX (Open Neural Network Exchange) format for your Ultralytics YOLO11 model before deploying it on NVIDIA Triton Inference Server offers several key benefits:

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

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

from ultralytics import YOLO

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

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

Can I run inference using the Ultralytics YOLO11 model on Triton Inference Server?

Yes, you can run inference using the Ultralytics YOLO11 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://localhost:8000/yolo", task="detect")

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

For an in-depth guide on setting up and running Triton Server with YOLO11, refer to the running triton inference server section.

How does Ultralytics YOLO11 compare to TensorFlow and PyTorch models for deployment?

Ultralytics YOLO11 offers several unique advantages compared to TensorFlow and PyTorch models for deployment:

  • Real-time Performance: Optimized for real-time object detection tasks, YOLO11 provides state-of-the-art accuracy and speed, making it ideal for applications requiring live video analytics.
  • Ease of Use: YOLO11 integrates seamlessly with Triton Inference Server and supports diverse export formats (ONNX, TensorRT, CoreML), making it flexible for various deployment scenarios.
  • Advanced Features: YOLO11 includes features like dynamic model loading, model versioning, and ensemble inference, which are crucial for scalable and reliable AI deployments.

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

📅 Created 11 months ago ✏️ Updated 22 days ago

コメント