> 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/yolov9.md).

# YOLOv9

YOLOv9 物体検出を Serverless Cloud API 経由で使用します

既存の YOLOv9 モデルは、次を通じて引き続き利用できます [Serverless Cloud API](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api) および [セルフホスト型 Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted). YOLOv9 の新しい重みのアップロードと学習は Roboflow ではサポートされていません。サポートされているアップロード対象のファミリーについては、次を参照してください [カスタム重みのアップロード](https://docs.roboflow.com/models/ja/moderunomi/upload-custom-weights.md).

セルフホスト型デプロイメントについては、次を参照してください [Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted).

YOLOv9 の入力サイズは、Roboflow の外部でモデルを学習するときに設定します（一般的な値: 640x640 または 1280x1280）。

## YOLOv9 API

{% 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 %}

### モデルを実行する

この例では、Roboflow の公開 YOLOv9 モデルを実行します。学習対象は [COCO](https://universe.roboflow.com/microsoft/coco) (`coco/18`）なので、そのまま動作します。既存のアップロード済みモデルを実行するには、その `{workspace}/{model-slug}` ID を使用します（ [バージョン、トレーニング、モデル](https://docs.roboflow.com/models/ja/versions-trainings-and-models.md)).

```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"))
result = client.infer(image, model_id="coco/18")

detections = sv.Detections.from_inference(result)

annotated = sv.BoxAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections)

cv2.imwrite("annotated.png", annotated)
```

<figure><img src="https://1194881119-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fcmo9mhfIjYrvFFy1U7dk%2Fuploads%2Fgit-blob-1d6450d657d1d20f13968e4e4500e5f31b5f448c%2Fyolov9-coco-detection.webp?alt=media" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

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

* `https://serverless.roboflow.com` Serverless Cloud 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 %}
