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

# YOLOv7

当社の YOLOv7 インスタンスセグメンテーション推論をサポートしています [Serverless Cloud API](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api)。Roboflow では YOLOv7 のトレーニングはサポートされていませんが、 [独自の重みをアップロードできます](/models/ja/moderunomi/upload-custom-weights.md) それらに対して推論を実行できます。

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

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

## YOLOv7 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をインストールし、 [supervision](https://supervision.roboflow.com/) マスクのデコードと描画に使用します:

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

{% endstep %}

{% step %}

### モデルを実行する

この例では、次で学習された公開 YOLOv7 インスタンスセグメンテーションモデルを実行します [コンクリート表面の欠陥](https://universe.roboflow.com/road-ywxxe/concrete-pugqq) (`concrete-pugqq/3`）、その後 supervision を使って予測マスクを描画します。独自の重みを提供するには、あなたの `{workspace}/{model-slug}` IDに置き換えてください（ [バージョン、トレーニング、モデル](/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/concrete-crack.jpg")

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
).configure(InferenceConfiguration(api_key_transport="header"))
results = client.infer(image, model_id="concrete-pugqq/3")

detections = sv.Detections.from_inference(results)

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

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

<figure><img src="/files/e6c55eaee047eb32d0cb6931b18f03e62e2b1361" 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) サーバー用。
* あなたの [Dedicated Deployment](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments) プライベートエンドポイント用のURL。
  {% endhint %}
