콘텐츠로 건너뛰기

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.



Watch: 시작하기 NVIDIA Triton 추론 서버.

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 추론 서버를 실행합니다:

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 서버 모델을 사용하여 추론을 실행합니다:

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 모델 리포지토리를 설정합니다:

    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

댓글