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

# YOLOv12

私たちは、独自の [サーバーレス・クラウドAPI](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api)。YOLOv12は5つのサイズ（`n`, `s`, `m`, `l`, `x`）で、物体検出タスクに対応しています。

セルフホスト型デプロイについては、 [Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted).

YOLOv12の入力サイズは、Roboflowでモデルをトレーニングするときに設定されます（一般的な値: 640x640 または 1280x1280）。

## YOLOv12 API

{% stepper %}
{% step %}

### APIキーを取得する

Roboflowアカウントを作成し、次の場所でキーを見つけてください: [Roboflow API設定ページ](https://app.roboflow.com/settings/api) そして、シェルで使えるようにします:

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

{% endstep %}

{% step %}

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

次をインストールしてください: [Inference SDK](https://docs.roboflow.com/reference/inference/inference-sdk) と [supervision](https://supervision.roboflow.com/) を使って、予測結果をデコードして可視化します:

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

{% endstep %}

{% step %}

### モデルを実行する

この例では、次のデータセットでトレーニングされた公開YOLOv12モデルを実行します: [ねじデータセット](https://universe.roboflow.com/erik-pe6au/rf-bolts) （ねじ、平ワッシャー、六角ナット）。独自の `{workspace}/{model-slug}` を使って、学習済み重みを実行してください（参照: [バージョン、トレーニング、モデル](/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/docs/bolts.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="erik-pe6au/bolts-uzqzc-4-yolo12s-t1")

detections = sv.Detections.from_inference(result)

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

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

<figure><img src="/files/2fd2d7e1232fedf95b8bb4a568fec6a56d8114ea" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

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