> 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/get-started/ja/gaido/run-model-serverless-api.md).

# モデルAPIエンドポイントを使用する

ハードウェアの準備は不要で、5分でRoboflowのクラウドGPU上でモデルを実行できます。

この [Serverless Cloud API](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api) Roboflow のクラウド上の GPU でモデルと Workflows を実行します。画像を送信すると結果が返ってきます。セットアップするハードウェアも、稼働し続けるサーバーも必要ありません。

このガイドでは、ゼロから5分でモデルを実行するところまで案内します。画像内のオブジェクトは名前を付けるだけで見つけられ、既製のモデルで日常的なオブジェクトを検出し、独自のモデルも実行できます。すべて同じ Serverless Cloud API エンドポイントに対して行います。

## 名前を付けてオブジェクトを見つける

モデルに次のような言葉をいくつか与えます `「タクシー」`, `「青いバス」`、または `「茂み」` すると、画像内の一致するすべてのオブジェクトの輪郭が描かれます。最初に設定や学習を行う必要はありません。これを実行します [SAM3](https://docs.roboflow.com/models/supported-models/sam3).

{% tabs %}
{% tab title="HTTP（Python）" icon="webhook" %}
{% stepper %}
{% step %}

### APIキーを取得する

Roboflow アカウントを作成し、キーは次の場所で見つけてください [Roboflow API 設定ページ](https://app.roboflow.com/settings/api) そしてシェルから利用できるようにします：

```bash
export ROBOFLOW_API_KEY="your-key-here"
```

{% endstep %}

{% step %}

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

`supervision` を導入します `cv2` と `numpy`:

```bash
pip install -U supervision
```

{% endstep %}

{% step %}

### モデルを実行する

次に POST リクエストを送信します `/sam3/concept_segment` これでモデルを実行します。 `sv.Detections.from_sam3` それらの結果を次の形式に変換します [`supervision`](https://supervision.roboflow.com) 描画できます：

```python
import os
import base64
import cv2
import requests
import supervision as sv

image = sv.load_image_from_url("https://media.roboflow.com/quickstart/traffic.jpg")
image_b64 = base64.b64encode(content).decode("utf-8")
h, w = image.shape[:2]

response = requests.post(
    "https://serverless.roboflow.com/sam3/concept_segment",
    headers={"Authorization": f"Bearer {os.environ['ROBOFLOW_API_KEY']}"},
    json={
        "image": {"type": "base64", "value": image_b64},
        "prompts": [
            {"type": "text", "text": "タクシー"},
            {"type": "text", "text": "青いバス"},
            {"type": "text", "text": "茂み"},
        ],
    },
)

detections = sv.Detections.from_sam3(response.json(), (w, h))
annotated = sv.MaskAnnotator().annotate(image.copy(), detections)
cv2.imwrite("sam3.jpg", annotated)
```

{% endstep %}
{% endstepper %}
{% endtab %}

{% tab title="SDK（Python）" icon="python" %}
{% stepper %}
{% step %}

### APIキーを取得する

Roboflow アカウントを作成し、キーは次の場所で見つけてください [Roboflow API 設定ページ](https://app.roboflow.com/settings/api) そしてシェルから利用できるようにします：

```bash
export ROBOFLOW_API_KEY="your-key-here"
```

{% endstep %}

{% step %}

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

この2つのパッケージでモデルを呼び出し、結果を描画します：

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

{% endstep %}

{% step %}

### モデルを実行する

この [Inference SDK](https://docs.roboflow.com/reference/inference/inference-sdk) 画像をクラウドに送信し、結果を返します。 `sv.Detections.from_sam3` それらの結果を次の形式に変換します [`supervision`](https://supervision.roboflow.com) 描画できます：

```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")
h, w = image.shape[:2]

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
).configure(InferenceConfiguration(api_key_transport="header"))

data = client.sam3_concept_segment(
    image,
    prompts=[
        {"type": "text", "text": "タクシー"},
        {"type": "text", "text": "青いバス"},
        {"type": "text", "text": "茂み"},
    ],
)

detections = sv.Detections.from_sam3(data, (w, h))
annotated = sv.MaskAnnotator().annotate(image.copy(), detections)
annotated = sv.BoxAnnotator().annotate(annotated, detections)
cv2.imwrite("sam3.jpg", annotated)
```

{% endstep %}
{% endstepper %}
{% endtab %}
{% endtabs %}

レスポンスには、各プロンプトごとに見つかった輪郭が一覧表示され、それぞれに信頼度スコアが付きます。 `sv.Detections.from_sam3` それらすべてを読み取ってくれます。

<figure><img src="https://2537277549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1YMZNIiZMBdlCHUDeZMP%2Fuploads%2Fgit-blob-fc88d211337fc1990e06fab3fc499075fdedd7c1%2Fserverless-sam3-out.jpg?alt=media" alt="Outlines around taxis, a blue bus, and bushes from text prompts"><figcaption><p>テキストプロンプトから輪郭を抽出したオブジェクト</p></figcaption></figure>

視覚プロンプト、例示ボックス、RLE 出力を含む完全な SAM3 API については、 [SAM3 ドキュメント](https://docs.roboflow.com/models/supported-models/sam3).

## 既製のモデルで日常的なオブジェクトを検出する

{% tabs %}
{% tab title="HTTP（Python）" icon="webhook" %}
名前付きオブジェクトの輪郭を取る代わりに、一般的なオブジェクトの周りにボックスを描画するには、 `POST /{project}/{version}` モデル ID を指定して `POST /sam3/concept_segment`。この例では既製の [RF-DETR](https://docs.roboflow.com/models/supported-models/rf-detr) モデルを使用します。これは車両、人、ペットなどの一般的なオブジェクトを検出できます。RF-DETR は Apache 2.0 であるため、商用利用は無料です：

```python
result = requests.post(
    "https://serverless.roboflow.com/coco/40",  # coco/40 は rfdetr-medium の別名
    data=image_b64,  # 本文には生の base64 を入れ、JSON ではありません
    headers={
        "Authorization": f"Bearer {os.environ['ROBOFLOW_API_KEY']}",
        "Content-Type": "application/x-www-form-urlencoded",
    },
).json()
detections = sv.Detections.from_inference(result)

print(f"Found {len(detections)} objects")

annotated = sv.BoxAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections)
cv2.imwrite("rf-detr.jpg", annotated)
```

{% endtab %}

{% tab title="SDK（Python）" icon="python" %}
名前付きオブジェクトの輪郭を取る代わりに、一般的なオブジェクトの周りにボックスを描画するには、 `client.infer()` モデル ID を指定して `client.sam3_concept_segment()`。この例では既製の [RF-DETR](https://docs.roboflow.com/models/supported-models/rf-detr) モデルを使用します。これは車両、人、ペットなどの一般的なオブジェクトを検出できます。RF-DETR は Apache 2.0 であるため、商用利用は無料です：

```python
result = client.infer(image, model_id="rfdetr-medium")
detections = sv.Detections.from_inference(result)

print(f"Found {len(detections)} objects")

annotated = sv.BoxAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections)
cv2.imwrite("rf-detr.jpg", annotated)
```

{% endtab %}
{% endtabs %}

<figure><img src="https://2537277549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1YMZNIiZMBdlCHUDeZMP%2Fuploads%2Fgit-blob-516089a73418852ced8eddbeeb1a94db1bc11421%2Fserverless-rfdetr-out.jpg?alt=media" alt="RF-DETR bounding boxes for cars, buses, people, and motorcycles"><figcaption><p>RF-DETR は車、バス、人、オートバイを検出します</p></figcaption></figure>

## 独自のモデル、または別のモデルを実行する

同じ `client.infer()` または `POST /{project}/{version}` 呼び出しで、任意のモデルをその `model_id`:

* Roboflow で学習したモデル。モデル ID（次の形式）をコピーします `{project}/{version}`を、次の場所のプロジェクトから取得してください [Roboflow アプリ](https://app.roboflow.com)
* 次の公開モデル [Roboflow Universe](https://docs.roboflow.com/datasets/universe/universe/what-is-roboflow-universe)
* 既製の [事前学習済みモデル](https://docs.roboflow.com/models/pretrained-aliases) をエイリアスで指定します。たとえば `rfdetr-nano`, `rfdetr-seg-medium`、または `yolo26l-640` （Inference SDK のみ）。RF-DETR は Apache 2.0 で、YOLO26 は AGPL-3.0 です。Roboflow にデプロイすると商用ライセンスが含まれます。詳細は [モデルライセンス](https://docs.roboflow.com/models/model-licenses)

## 次に進むには

クラウド上でモデルを実行しています。ここから次のことができます：

* 同じモデルを自分のハードウェアで実行する。詳細は [モデルをローカルで実行する](/get-started/ja/gaido/run-a-model-locally.md)
* 大規模モデルと安定したトラフィック向けに専用のシングルテナントエンドポイントを取得するには [Dedicated Deployments](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments)
* モデルとロジックをアプリケーションに連結するには [Workflows](https://docs.roboflow.com/workflows)
* 各リクエストのコストを次の場所で把握する [Serverless の料金ページ](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api/pricing)
