> 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-3.md).

# Roboflow 3.0 オブジェクト検出

## Roboflow 3.0 オブジェクト検出

Roboflow 3.0 は Roboflow の社内モデルアーキテクチャです。Roboflow 3.0 モデルは Roboflow プラットフォームで学習し、次を通じてデプロイします [サーバーレスホスト型 API](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api). 以下のサンプルは Roboflow の公開 [COCO モデル](https://universe.roboflow.com/microsoft/coco) (`coco/3`) すぐに試せます。セルフホスト型デプロイについては、こちらを参照してください [Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted).

### コード例

{% 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 %}
**モデルを実行する**

サンプル画像で検出を実行し、ボックスとラベルを注釈します：

```python
import os
import cv2
import supervision as sv
from inference_sdk import InferenceHTTPClient

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"],
)
result = client.infer(image, model_id="coco/3")

detections = sv.Detections.from_inference(result)

annotated = sv.BoxAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections)
cv2.imwrite("output.png", annotated)
```

<figure><img src="/files/07e55c741a0ae0cf8383ae8a2e358b0e6ef0073f" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

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

* `https://serverless.roboflow.com` Serverless Hosted 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 %}

## Roboflow 3.0 インスタンスセグメンテーション

Roboflow 3.0 のインスタンスセグメンテーションモデルを学習し、その後、 `your-project/1` をあなた自身のものに置き換えてください `{workspace}/{model-slug}` の [バージョン、学習、モデル](/models/ja/versions-trainings-and-models.md)）。API キーを設定し、上記のとおり依存関係をインストールしてください。

### コード例

```python
import os
import cv2
import supervision as sv
from inference_sdk import InferenceHTTPClient

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"],
)
# 事前学習済みのエイリアスはありません。独自モデルを学習し、「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("output.png", annotated)
```

## Roboflow 3.0 キーポイント検出

この例では公開の [rf-handpose](https://universe.roboflow.com/erik-pe6au/rf-handpose) 手のキーポイントモデルで、その後 21 点の手のスケルトンを描画します。あなた自身のものに差し替えてください `{workspace}/{model-slug}`。API キーを設定し、上記のとおり依存関係をインストールしてください。

### コード例

```python
import os
import cv2
import supervision as sv
from inference_sdk import InferenceHTTPClient

image = sv.load_image_from_url("https://media.roboflow.com/docs/hand.jpg")

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)
result = client.infer(image, model_id="rf-handpose/1")

key_points = sv.KeyPoints.from_inference(result)

# 手のスケルトン: 手首 (0)、親指 (1-4)、人差し指 (5-8)、中指 (9-12)、薬指 (13-16)、小指 (17-20)
hand_edges = [
    (0, 1), (1, 2), (2, 3), (3, 4),
    (0, 5), (5, 6), (6, 7), (7, 8),
    (5, 9), (9, 10), (10, 11), (11, 12),
    (9, 13), (13, 14), (14, 15), (15, 16),
    (13, 17), (17, 18), (18, 19), (19, 20), (0, 17),
]
annotated = image.copy()
vertices = key_points.xy[0].astype(int)
for start, end in hand_edges:
    cv2.line(annotated, tuple(vertices[start]), tuple(vertices[end]), (255, 0, 0), 2)
annotated = sv.VertexAnnotator(color=sv.Color.GREEN, radius=5).annotate(annotated, key_points)
cv2.imwrite("output.png", annotated)
```

<figure><img src="/files/a54763fbb90f6d395972f354ecb9fecdd4f7751f" alt=""><figcaption></figcaption></figure>

## Roboflow 3.0 分類

分類レスポンスには信頼度付きのクラス予測の一覧が含まれるため、可視化は適用できません。レスポンスから最上位クラスを直接読み取ります。次を置き換えてください `your-project/1` を、学習済みのモデル ID に置き換え、API キーを設定して上記のとおり依存関係をインストールしてください。

### コード例

```python
import os
import supervision as sv
from inference_sdk import InferenceHTTPClient

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"],
)
# 事前学習済みのエイリアスはありません。独自モデルを学習し、「your-project/1」をモデル ID に置き換えてください。
result = client.infer(image, model_id="your-project/1")

print(f"Top class: {result['top']} ({result['confidence']:.4f})")
```
