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

# Roboflow 2.0

Roboflow 2.0 のセマンティックセグメンテーションモデルを Serverless Hosted API 経由で使用します

Roboflow 2.0 は DeepLabv3 ベースのセマンティックセグメンテーションモデルです。Roboflow プラットフォームで Roboflow 2.0 モデルをトレーニングし、以下を通じてデプロイします。 [サーバーレス Cloud API](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api).

セルフホスト型でデプロイする場合は、 [Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted).

## Roboflow 2.0 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/deployment/self-hosted/self-hosted) と [supervision](https://supervision.roboflow.com/):

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

{% endstep %}

{% step %}

### モデルを実行する

トレーニング済みの Roboflow 2.0 セマンティックセグメンテーションモデルで推論を実行し、注釈付き PNG を書き出します。モデルは次の `{workspace}/{model-slug}` ID で指定します（ [バージョン、トレーニング、モデル](https://docs.roboflow.com/models/ja/versions-trainings-and-models.md)).

`sv.Detections.from_inference` （supervision 0.32.0 以降）は、結果内の各クラスを1つの検出に変換します。そのマスクは該当クラスの全ピクセルを覆い、結果の `class_map`からクラス名が付与されます。クラス ID 0（背景）は除外されます。マスクが入力画像と同じサイズになるよう、クライアント側の縮小は無効にしてください。

```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/quickstart/traffic.jpg")

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
).configure(InferenceConfiguration(
    api_key_transport="header",
    client_downsizing_disabled=True,
))
# 事前学習済みモデルのエイリアスはありません。独自のモデルをトレーニングし、"your-project/1" をモデル ID に置き換えてください。
result = client.infer(image, model_id="your-project/1")

detections = sv.Detections.from_inference(result)

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

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

{% endstep %}
{% endstepper %}

{% hint style="info" %}
デプロイ先に合わせて `api_url` を設定します。

* `https://serverless.roboflow.com` はサーバーレス Cloud API 用です。
* `http://localhost:9001` ローカルの [推論](https://docs.roboflow.com/deployment/self-hosted/self-hosted) サーバー。
* 専用の [デプロイ](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments) プライベートエンドポイントのURL。
  {% endhint %}
