> 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

YOLOv12 物体検出モデルを Serverless Cloud API 経由で使用します

当社の [サーバーレス・クラウド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}` に差し替えて、学習済み重みを実行します（ [バージョン、トレーニング、モデル](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/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="https://1194881119-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fcmo9mhfIjYrvFFy1U7dk%2Fuploads%2Fgit-blob-c2ef4d06be0aef1325d9481411947abcd13d9035%2Fyolov12-screws-detection.webp?alt=media" 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 %}

## カスタム重みをアップロード

Roboflow外で学習したYOLOv12モデルを実行するには、次を使ってその重みをProjectにアップロードします [Roboflow CLI](https://docs.roboflow.com/reference/platform/cli/install-and-set-up-the-cli):

```bash
roboflow upload_model -p my-project -v 1 -t yolov12n -m ./runs/detect/train
```

設定 `-t` をモデルのサイズに合わせて（例: `yolov12s`）。 [カスタム重みをアップロード](https://docs.roboflow.com/models/ja/moderunomi/upload-custom-weights.md) Python SDKとトレーニング版の要件については参照してください。

## ライセンス

YOLOv12はAGPL-3.0で公開されています。商用利用においての意味は次のとおりです:

* **Roboflow Cloudでは:** 無料プランを含むすべてのユーザーに商用ライセンスが含まれます。
* **セルフホストの場合:** Enterpriseライセンスのアドオンが必要です。もしくは、アプリケーションをAGPL-3.0でオープンソース化する必要があります。
* **より寛容な代替案:** [RF-DETR](https://docs.roboflow.com/models/ja/supported-models/rf-detr.md) はApache 2.0で、どこでも商用利用可能です。

詳細は [RoboflowのUltralyticsライセンス](https://roboflow.com/ultralytics) をご覧ください。
