コンテンツにスキップ

Ultralytics HUB推論API

モデルをトレーニングした後、共有推論APIを無料で使用できます。Proユーザーの場合は、専用推論APIにアクセスできます。Ultralytics HUB推論APIを使用すると、Ultralytics YOLO環境をローカルにインストールして設定しなくても、REST APIを通じて推論を実行できます。

Ultralytics HUBのモデルページにあるデプロイタブのスクリーンショット。専用推論APIカードと共有推論APIカードを指す矢印付き


見る: Ultralytics HUB推論APIのウォークスルー

専用推論API

高い需要と広範な関心にお応えして、Ultralytics HUB 専用推論APIを発表いたします。当社のProユーザー向けに、専用環境でのシングルクリックデプロイを提供します。

この機能は、パブリックベータ期間中、Pro Planの一部として無料で提供します。将来的には有料プランも検討しています。

  • グローバルカバレッジ: 世界中の38の地域に展開されており、どの場所からでも低遅延アクセスを保証します。Google Cloudリージョンの完全なリストを参照してください
  • Google Cloud Runによるサポート: Google Cloud Runによってサポートされており、無限にスケーラブルで信頼性の高いインフラストラクチャを提供します。
  • 高速: Ultralyticsのテストに基づくと、近隣地域からの640解像度でのYOLOv8n推論では、100ms未満の遅延が可能です。
  • 強化されたセキュリティ: データを保護し、業界標準への準拠を保証するための堅牢なセキュリティ機能を提供します。Google Cloudセキュリティの詳細はこちら

Ultralytics HUBの専用推論APIを使用するには、Start Endpointボタンをクリックします。次に、以下のガイドで説明されている固有のエンドポイントURLを使用します。

Ultralytics HUBのモデルページにあるデプロイタブのスクリーンショット。専用推論APIカードのStart Endpointボタンを指す矢印付き

ヒント

最適なパフォーマンスを得るには、ドキュメントに記載されているように、レイテンシーが最も低いリージョンを選択してください。

専用エンドポイントをシャットダウンするには、Stop Endpointボタンをクリックします。

Ultralytics HUBのモデルページにあるデプロイタブのスクリーンショット。専用推論APIカードのStop Endpointボタンを指す矢印付き

共有推論API

Ultralytics HUBの共有推論APIを使用するには、以下のガイドに従ってください。

Ultralytics HUB Shared Inference APIには、以下の使用制限があります。

  • 100 calls / hour

Python

Pythonを使用してUltralytics HUB推論APIにアクセスするには、次のコードを使用します。

import requests

# API URL
url = "https://predict.ultralytics.com"

# Headers, use actual API_KEY
headers = {"x-api-key": "API_KEY"}

# Inference arguments (use actual MODEL_ID)
data = {"model": "https://hub.ultralytics.com/models/MODEL_ID", "imgsz": 640, "conf": 0.25, "iou": 0.45}

# Load image and send request
with open("path/to/image.jpg", "rb") as image_file:
    files = {"file": image_file}
    response = requests.post(url, headers=headers, files=files, data=data)

print(response.json())

置換 MODEL_ID 目的のモデルIDを指定して、 API_KEY 実際のAPIキーを使用して、 path/to/image.jpg 推論を実行する画像のパスを指定します。

当社の製品をご利用の場合 専用推論APIは、以下を置き換えます。 url 同様に。

cURL

cURLを使用してUltralytics HUB推論APIにアクセスするには、次のコードを使用します。

curl -X POST "https://predict.ultralytics.com" \
  -H "x-api-key: API_KEY" \
  -F "model=https://hub.ultralytics.com/models/MODEL_ID" \
  -F "file=@/path/to/image.jpg" \
  -F "imgsz=640" \
  -F "conf=0.25" \
  -F "iou=0.45"

置換 MODEL_ID 目的のモデルIDを指定して、 API_KEY 実際のAPIキーを使用して、 path/to/image.jpg 推論を実行する画像のパスを指定します。

当社の製品をご利用の場合 専用推論APIは、以下を置き換えます。 url 同様に。

引数

利用可能な推論引数の完全なリストについては、以下の表を参照してください。

引数 デフォルト 種類 説明
file file 推論に使用される画像またはビデオファイル。
imgsz 640 int 入力画像のサイズ、有効範囲は 32 - 1280 ピクセル。
conf 0.25 float 予測の信頼度閾値、有効範囲 0.01 - 1.0.
iou 0.45 float Intersection over Union(IoU) (IoU)閾値、有効範囲 0.0 - 0.95.

応答

Ultralytics HUB推論APIは、JSON応答を返します。

分類

分類モデル

from ultralytics import YOLO

# Load model
model = YOLO("yolov8n-cls.pt")

# Run inference
results = model("image.jpg")

# Print image.jpg results in JSON format
print(results[0].to_json())
curl -X POST "https://predict.ultralytics.com" \
  -H "x-api-key: API_KEY" \
  -F "model=https://hub.ultralytics.com/models/MODEL_ID" \
  -F "file=@/path/to/image.jpg" \
  -F "imgsz=640" \
  -F "conf=0.25" \
  -F "iou=0.45"
import requests

# API URL
url = "https://predict.ultralytics.com"

# Headers, use actual API_KEY
headers = {"x-api-key": "API_KEY"}

# Inference arguments (use actual MODEL_ID)
data = {"model": "https://hub.ultralytics.com/models/MODEL_ID", "imgsz": 640, "conf": 0.25, "iou": 0.45}

# Load image and send request
with open("path/to/image.jpg", "rb") as image_file:
    files = {"file": image_file}
    response = requests.post(url, headers=headers, files=files, data=data)

print(response.json())
{
  "images": [
    {
      "results": [
        {
          "class": 0,
          "name": "person",
          "confidence": 0.92
        }
      ],
      "shape": [
        750,
        600
      ],
      "speed": {
        "inference": 200.8,
        "postprocess": 0.8,
        "preprocess": 2.8
      }
    }
  ],
  "metadata": ...
}

検出

検出モデル

from ultralytics import YOLO

# Load model
model = YOLO("yolov8n.pt")

# Run inference
results = model("image.jpg")

# Print image.jpg results in JSON format
print(results[0].to_json())
curl -X POST "https://predict.ultralytics.com" \
  -H "x-api-key: API_KEY" \
  -F "model=https://hub.ultralytics.com/models/MODEL_ID" \
  -F "file=@/path/to/image.jpg" \
  -F "imgsz=640" \
  -F "conf=0.25" \
  -F "iou=0.45"
import requests

# API URL
url = "https://predict.ultralytics.com"

# Headers, use actual API_KEY
headers = {"x-api-key": "API_KEY"}

# Inference arguments (use actual MODEL_ID)
data = {"model": "https://hub.ultralytics.com/models/MODEL_ID", "imgsz": 640, "conf": 0.25, "iou": 0.45}

# Load image and send request
with open("path/to/image.jpg", "rb") as image_file:
    files = {"file": image_file}
    response = requests.post(url, headers=headers, files=files, data=data)

print(response.json())
{
  "images": [
    {
      "results": [
        {
          "class": 0,
          "name": "person",
          "confidence": 0.92,
          "box": {
            "x1": 118,
            "x2": 416,
            "y1": 112,
            "y2": 660
          }
        }
      ],
      "shape": [
        750,
        600
      ],
      "speed": {
        "inference": 200.8,
        "postprocess": 0.8,
        "preprocess": 2.8
      }
    }
  ],
  "metadata": ...
}

OBB

OBBモデル

from ultralytics import YOLO

# Load model
model = YOLO("yolov8n-obb.pt")

# Run inference
results = model("image.jpg")

# Print image.jpg results in JSON format
print(results[0].tojson())
curl -X POST "https://predict.ultralytics.com" \
  -H "x-api-key: API_KEY" \
  -F "model=https://hub.ultralytics.com/models/MODEL_ID" \
  -F "file=@/path/to/image.jpg" \
  -F "imgsz=640" \
  -F "conf=0.25" \
  -F "iou=0.45"
import requests

# API URL
url = "https://predict.ultralytics.com"

# Headers, use actual API_KEY
headers = {"x-api-key": "API_KEY"}

# Inference arguments (use actual MODEL_ID)
data = {"model": "https://hub.ultralytics.com/models/MODEL_ID", "imgsz": 640, "conf": 0.25, "iou": 0.45}

# Load image and send request
with open("path/to/image.jpg", "rb") as image_file:
    files = {"file": image_file}
    response = requests.post(url, headers=headers, files=files, data=data)

print(response.json())
{
  "images": [
    {
      "results": [
        {
          "class": 0,
          "name": "person",
          "confidence": 0.92,
          "box": {
            "x1": 374.85565,
            "x2": 392.31824,
            "x3": 412.81805,
            "x4": 395.35547,
            "y1": 264.40704,
            "y2": 267.45728,
            "y3": 150.0966,
            "y4": 147.04634
          }
        }
      ],
      "shape": [
        750,
        600
      ],
      "speed": {
        "inference": 200.8,
        "postprocess": 0.8,
        "preprocess": 2.8
      }
    }
  ],
  "metadata": ...
}

セグメンテーション

セグメンテーションモデル

from ultralytics import YOLO

# Load model
model = YOLO("yolov8n-seg.pt")

# Run inference
results = model("image.jpg")

# Print image.jpg results in JSON format
print(results[0].tojson())
curl -X POST "https://predict.ultralytics.com" \
  -H "x-api-key: API_KEY" \
  -F "model=https://hub.ultralytics.com/models/MODEL_ID" \
  -F "file=@/path/to/image.jpg" \
  -F "imgsz=640" \
  -F "conf=0.25" \
  -F "iou=0.45"
import requests

# API URL
url = "https://predict.ultralytics.com"

# Headers, use actual API_KEY
headers = {"x-api-key": "API_KEY"}

# Inference arguments (use actual MODEL_ID)
data = {"model": "https://hub.ultralytics.com/models/MODEL_ID", "imgsz": 640, "conf": 0.25, "iou": 0.45}

# Load image and send request
with open("path/to/image.jpg", "rb") as image_file:
    files = {"file": image_file}
    response = requests.post(url, headers=headers, files=files, data=data)

print(response.json())
{
  "images": [
    {
      "results": [
        {
          "class": 0,
          "name": "person",
          "confidence": 0.92,
          "box": {
            "x1": 118,
            "x2": 416,
            "y1": 112,
            "y2": 660
          },
          "segments": {
            "x": [
              266.015625,
              266.015625,
              258.984375,
              ...
            ],
            "y": [
              110.15625,
              113.67188262939453,
              120.70311737060547,
              ...
            ]
          }
        }
      ],
      "shape": [
        750,
        600
      ],
      "speed": {
        "inference": 200.8,
        "postprocess": 0.8,
        "preprocess": 2.8
      }
    }
  ],
  "metadata": ...
}

ポーズ

ポーズモデル

from ultralytics import YOLO

# Load model
model = YOLO("yolov8n-pose.pt")

# Run inference
results = model("image.jpg")

# Print image.jpg results in JSON format
print(results[0].tojson())
curl -X POST "https://predict.ultralytics.com" \
  -H "x-api-key: API_KEY" \
  -F "model=https://hub.ultralytics.com/models/MODEL_ID" \
  -F "file=@/path/to/image.jpg" \
  -F "imgsz=640" \
  -F "conf=0.25" \
  -F "iou=0.45"
import requests

# API URL
url = "https://predict.ultralytics.com"

# Headers, use actual API_KEY
headers = {"x-api-key": "API_KEY"}

# Inference arguments (use actual MODEL_ID)
data = {"model": "https://hub.ultralytics.com/models/MODEL_ID", "imgsz": 640, "conf": 0.25, "iou": 0.45}

# Load image and send request
with open("path/to/image.jpg", "rb") as image_file:
    files = {"file": image_file}
    response = requests.post(url, headers=headers, files=files, data=data)

print(response.json())
{
  "images": [
    {
      "results": [
        {
          "class": 0,
          "name": "person",
          "confidence": 0.92,
          "box": {
            "x1": 118,
            "x2": 416,
            "y1": 112,
            "y2": 660
          },
          "keypoints": {
            "visible": [
              0.9909399747848511,
              0.8162999749183655,
              0.9872099757194519,
              ...
            ],
            "x": [
              316.3871765136719,
              315.9374694824219,
              304.878173828125,
              ...
            ],
            "y": [
              156.4207763671875,
              148.05775451660156,
              144.93240356445312,
              ...
            ]
          }
        }
      ],
      "shape": [
        750,
        600
      ],
      "speed": {
        "inference": 200.8,
        "postprocess": 0.8,
        "preprocess": 2.8
      }
    }
  ],
  "metadata": ...
}


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

コメント