> 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 経由で使用します

既存のYOLOv7モデルは、以下を通じて引き続き利用できます [サーバーレス Cloud API](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api) および [セルフホスト型推論](https://docs.roboflow.com/deployment/self-hosted/self-hosted)。YOLOv7の新しい重みのアップロードと学習は、Roboflowではサポートされていません。対応しているアップロードファミリーについては、以下を参照してください [カスタム重みをアップロード](https://docs.roboflow.com/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（以下を参照 [バージョン、学習、モデル](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/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="https://1194881119-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fcmo9mhfIjYrvFFy1U7dk%2Fuploads%2Fgit-blob-d39021d44de10c5eeece73abfef23ec8ad7322dd%2Fyolov7-concrete-segmentation.webp?alt=media" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

{% hint style="info" %}
設定する `api_url` を、デプロイ先に合わせてください:

* `https://serverless.roboflow.com` サーバーレス Cloud 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 %}
