> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/models/ja/supported-models/yolo-world.md).

# YOLO-World

YOLO-Worldは、学習なしで任意のテキストクラス名から物体を検出するオープンボキャブラリの物体検出モデルです。YOLO-World の推論は、当社の [サーバーレスクラウドAPI](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api).

YOLO-World の実行方法の詳細については、 [推論ドキュメント](https://docs.roboflow.com/deployment/self-hosted/self-hosted).

## YOLO-World API

HTTPエンドポイントを直接使って YOLO-World を実行するには、 `curl`、または [`inference-sdk`](https://docs.roboflow.com/reference/inference/inference-sdk) ラッパーを使用します。

{% tabs %}
{% tab title="HTTP（curl）" icon="webhook" %}
{% stepper %}
{% step %}

### APIキーを取得する

Roboflow アカウントを作成し、 [Roboflow API 設定ページ](https://app.roboflow.com/settings/api) でキーを見つけ、シェルで利用できるようにします。

```bash
export ROBOFLOW_API_KEY="your-key-here"
```

{% endstep %}

{% step %}

### モデルを実行する

次を呼び出します `/yolo_world/infer` エンドポイントを `curl`:

```bash
curl --location 'https://serverless.roboflow.com/yolo_world/infer' \\
  --header 'Content-Type: application/json' \\
  --header "Authorization: Bearer $ROBOFLOW_API_KEY" \\
  --data '{
    "image": {"type": "url", "value": "https://media.roboflow.com/quickstart/traffic.jpg"},
    "text": ["car", "truck"],
    "yolo_world_version_id": "v2-s",
    "confidence": 0.05
  }'
```

{% endstep %}
{% endstepper %}
{% endtab %}

{% tab title="SDK（Python）" icon="python" %}
{% stepper %}
{% step %}

### APIキーを取得する

Roboflow アカウントを作成し、 [Roboflow API 設定ページ](https://app.roboflow.com/settings/api) でキーを見つけ、シェルで利用できるようにします。

```bash
export ROBOFLOW_API_KEY="your-key-here"
```

{% endstep %}

{% step %}

### 依存関係をインストールする

SDK と [supervision](https://supervision.roboflow.com/):

```bash
pip install -U inference-sdk supervision
```

{% endstep %}

{% step %}

### モデルを実行する

YOLO-World をカスタムクラス名で実行し、その後、supervision で予測をデコードして可視化します。

```python
import os
import cv2
import supervision as sv
from inference_sdk import InferenceHTTPClient, InferenceConfiguration

image = sv.load_image_from_url("https://media.roboflow.com/quickstart/traffic.jpg")

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
).configure(InferenceConfiguration(api_key_transport="header"))

results = client.infer_from_yolo_world(
    inference_input=image,
    class_names=["car", "truck"],
    model_version="v2-s",
    confidence=0.05,
)

detections = sv.Detections.from_inference(results[0])

labels = [
    f"{name} {conf:.2f}"
    for name, conf in zip(detections.data["class_name"], detections.confidence)
]
annotated = sv.BoxAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections, labels=labels)
cv2.imwrite("annotated.png", annotated)
```

<figure><img src="/files/926228b5a1828397249ea518f38492080b3b622b" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}
{% endtab %}
{% endtabs %}

この `class_names` 引数には、任意のクラス名のリストを指定できます。利用可能な `model_version` の値: `v2-s`, `v2-m`, `v2-l`, `v2-x`, `s`, `m`, `l`, `x`.

## YOLO-World の推論速度

レイテンシは [Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) を用いて、NVIDIA L4 1基、バッチサイズ1、ウォームアップ後の平均として測定しました。

<table data-search="false"><thead><tr><th>モデル</th><th>レイテンシ（ms）</th></tr></thead><tbody><tr><td><code>yolo-world</code></td><td>12.4</td></tr></tbody></table>

で測定しました `v2-s` 2クラスのバリアント。クラスリストを設定するとテキストエンコーダーが1回実行されますが、フレームごとに繰り返されないため、この図には含めていません。

{% hint style="info" %}
設定する `api_url` をデプロイ先に合わせます:

* `https://serverless.roboflow.com` サーバーレスクラウドAPI用。
* `http://localhost:9001` ローカルの [Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) サーバー用。
* あなたの [専用デプロイメント](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments) プライベートエンドポイント用のURL。
  {% endhint %}

## セルフホストの Inference で YOLO-World を実行する

YOLO-World は、自身のハードウェア上でも実行できます。 [`inference`](https://docs.roboflow.com/deployment/self-hosted/self-hosted) パッケージでインプロセス読み込みするか、ローカルの Inference サーバーによって提供できます。高性能なハードウェア（たとえば V100 GPU）ではリアルタイムで動作するため、動画用途に実用的です。

{% tabs %}
{% tab title="Inference（ネイティブ）" icon="server" %}

```bash
pip install "inference[yolo-world]" supervision
```

```python
import cv2
import supervision as sv

from inference.models.yolo_world.yolo_world import YOLOWorld

image = cv2.imread("image.jpeg")

model = YOLOWorld(model_id="yolo_world/l")
classes = ["person", "backpack", "dog"]
results = model.infer("image.jpeg", text=classes, confidence=0.03)[0]

detections = sv.Detections.from_inference(results)
labels = [classes[class_id] for class_id in detections.class_id]

annotated = sv.BoxAnnotator().annotate(scene=image, detections=detections)
annotated = sv.LabelAnnotator().annotate(
    scene=annotated, detections=detections, labels=labels
)
sv.plot_image(annotated)
```

{% endtab %}

{% tab title="ローカル Inference サーバー" icon="docker" %}

```bash
pip install inference inference-sdk
inference server start  # http://localhost:9001 を提供
```

```python
import os
from inference_sdk import InferenceHTTPClient

client = InferenceHTTPClient(
    api_url="http://127.0.0.1:9001",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)

results = client.infer_from_yolo_world(
    inference_input=["https://media.roboflow.com/dog.jpeg"],
    class_names=["person", "backpack", "dog"],
    model_version="l",
    confidence=0.1,
)[0]
```

{% endtab %}

{% tab title="動画" icon="video" %}
YOLO-World ブロックを Workflow に追加し、検出したいクラスを設定します。次に、次のクライアントを使って、その Workflow にウェブカメラ、カメラフィード、または動画ファイルをストリーミングします。 [Inference SDK WebRTC クライアント](https://docs.roboflow.com/workflows/deploy/video-processing).
{% endtab %}
{% endtabs %}

ネイティブパッケージでは、YOLO-World のチェックポイントは `yolo_world/<version>`として識別されます。 `<version>` は `s`, `m`, `l`, `x`, `v2-s`, `v2-m`, `v2-l`, `v2-x`のいずれかです。 `v2-` チェックポイントは新しく、評価指標でもより良いスコアを出します。

{% hint style="info" %}
多くのゼロショット検出器と同様に、YOLO-World は一般的な物体（車、人、犬）に最も強く、狭く粒度の細かいカテゴリには弱いです。プロンプトの表現を試して、あなたのシーンに何が合うかを見つけてください。
{% endhint %}
