> 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/roboflow/roboflow-jp/guides/run-model-serverless-api.md).

# Model API Endpoint を使用

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

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

## 名前を指定してオブジェクトを見つける

モデルに次のような単語をいくつか与えます `「taxi」`, `「青いバス」`、または `「茂み」` すると、画像内の一致するオブジェクトすべてを輪郭で囲みます。最初にセットアップや学習は不要です。これは動作します [SAM3](/roboflow/roboflow-jp/depuroi/supported-models/sam3.md).

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

### API Key を取得する

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 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
import numpy as np

content = requests.get("https://media.roboflow.com/quickstart/traffic.jpg").content
image = cv2.imdecode(np.frombuffer(content, np.uint8), cv2.IMREAD_COLOR)
image_b64 = base64.b64encode(content).decode("utf-8")
h, w = image.shape[:2]

response = requests.post(
    "https://serverless.roboflow.com/sam3/concept_segment",
    params={"api_key": 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 Key を取得する

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

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

{% endstep %}

{% step %}

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

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

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

{% endstep %}

{% step %}

### モデルを実行する

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

```python
import os
import cv2
import numpy as np
import requests
import supervision as sv
from inference_sdk import InferenceHTTPClient

content = requests.get("https://media.roboflow.com/quickstart/traffic.jpg").content
image = cv2.imdecode(np.frombuffer(content, np.uint8), cv2.IMREAD_COLOR)
h, w = image.shape[:2]

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

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="/files/473548789b9cde540969fd77649ce962f072580d" alt="Outlines around taxis, a blue bus, and bushes from text prompts"><figcaption><p>テキストプロンプトから輪郭を描かれたオブジェクト</p></figcaption></figure>

visual prompts、exemplar boxes、RLE 出力を含む完全な SAM3 API については、 [SAM3 ドキュメント](/roboflow/roboflow-jp/depuroi/supported-models/sam3.md).

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

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

```python
result = requests.post(
    "https://serverless.roboflow.com/coco/40",  # coco/40 は rfdetr-medium のエイリアスです
    params={"api_key": os.environ["ROBOFLOW_API_KEY"]},
    data=image_b64,  # ボディ内の生の base64 で、JSON ではありません
    headers={"Content-Type": "application/x-www-form-urlencoded"},
).json()
detections = sv.Detections.from_inference(result)

print(f"{len(detections)}個のオブジェクトを検出しました")

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](/roboflow/roboflow-jp/depuroi/supported-models/rf-detr.md) モデルを使用します。このモデルは、車両、人、ペットなどの一般的なオブジェクトを検出できます:

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

print(f"{len(detections)}個のオブジェクトを検出しました")

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

{% endtab %}
{% endtabs %}

<figure><img src="/files/5182cde87506d418a6a45c189d9d2458b08530d3" 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 app](https://app.roboflow.com)
* 次の公開モデル [Roboflow Universe](/roboflow/roboflow-jp/universe/what-is-roboflow-universe.md)
* 既製の [事前学習済みモデル](https://inference.roboflow.com/quickstart/aliases/) を、次のようなエイリアスで `rfdetr-nano`, `rfdetr-seg-medium`、または `yolo26l-640` (推論 SDK のみ)

## 次に進む場所

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

* 同じモデルを自分のハードウェアで実行する。参照 [Run a Model Locally](/roboflow/roboflow-jp/guides/run-a-model-locally.md)
* 大規模モデルと安定したトラフィック向けに、プライベートなシングルテナントのエンドポイントを取得するには [Dedicated Deployments](/roboflow/roboflow-jp/depuroi/dedicated-deployments.md)
* モデルとロジックをアプリケーションに連結するには [Workflows](/roboflow/roboflow-jp/workflows/what-is-workflows.md)
* 各リクエストのコストを、で把握する [Serverless pricing page](/roboflow/roboflow-jp/depuroi/serverless-hosted-api-v2/pricing.md)
