> 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

当社の [Serverless Hosted 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）。

## コード例

{% 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) （screw、flat-washer、hex-nut）。独自の `{workspace}/{model-slug}` を使用して、学習済み重みを実行します（参照: [バージョン、学習、モデル](/models/ja/versions-trainings-and-models.md)).

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

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"],
)
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` Serverless Hosted 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 %}
