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

# YOLOv5

当社のサービス経由で、YOLOv5の物体検出およびインスタンスセグメンテーションの推論をサポートしています [サーバーレスホスト型 API](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api) およびセルフホスト型の [Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted)。RoboflowではYOLOv5の学習はサポートされていませんが、 [学習済みの重みをアップロードする](/models/ja/moderunomi/upload-custom-weights.md) (`model_type="yolov5"`）を既存のプロジェクトで使用し、任意のデプロイ先で提供できます。Roboflowで学習した検出器については、 [RF-DETR](/models/ja/supported-models/rf-detr.md), [YOLO26](/models/ja/supported-models/yolo26.md)、または [YOLO11](/models/ja/supported-models/yolo11.md).

YOLOv5の入力サイズは、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 %}

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

SDK と [supervision](https://supervision.roboflow.com/) デコードおよびアノテーション用：

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

{% endstep %}

{% step %}

### モデルを実行する

次のものに差し替えてください： `{workspace}/{model-slug}` アップロードしたYOLOv5モデルのID（参照 [バージョン、学習、モデル](/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/quickstart/traffic.jpg")

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)
result = client.infer(image, model_id="your-workspace/your-model-slug")

detections = sv.Detections.from_inference(result)

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

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

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