> 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/deploy/supported-models/roboflow-3.md).

# Roboflow 3.0

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

Roboflow 3.0 は Roboflow 独自のモデルアーキテクチャです。Roboflow プラットフォーム上で Roboflow 3.0 モデルを学習し、次を通じてデプロイします [Serverless Hosted API](/roboflow/roboflow-jp/deploy/serverless-hosted-api-v2.md)。以下のサンプルは Roboflow の公開 [COCO モデル](https://universe.roboflow.com/microsoft/coco) (`coco/3`）なので、すぐに試せます。セルフホスト型デプロイについては、次を参照してください [Roboflow Inference](https://inference.roboflow.com/).

### コードサンプル

{% stepper %}
{% step %}
**API Key を取得する**

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

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

{% endstep %}

{% step %}
**依存関係をインストールする**

次をインストールします: [Inference SDK](https://inference.roboflow.com/) と [supervision](https://supervision.roboflow.com/):

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

{% endstep %}

{% step %}
**モデルを実行する**

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

```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)

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/0d467e847b49959738c8a9fc7445ffb84d2d5329" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

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

* `https://serverless.roboflow.com` Serverless Hosted API 用。
* `http://localhost:9001` ローカルの [Inference](https://inference.roboflow.com/) サーバー用。
* あなたの [Dedicated Deployment](/roboflow/roboflow-jp/deploy/dedicated-deployments.md) プライベートエンドポイントの URL。
  {% endhint %}

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

Roboflow 3.0 インスタンスセグメンテーションモデルを学習し、次に置き換えます `your-project/1` ご自身の `{workspace}/{model-slug}` ID で呼び出すことができます（ [Versions, Trainings, and Models](/roboflow/roboflow-jp/train/versions-trainings-and-models.md)）。API キーを設定し、上記のとおり依存関係をインストールしてください。

### コードサンプル

```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)

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 numpy as np
import requests
import supervision as sv
from inference_sdk import InferenceHTTPClient

content = requests.get("https://media.roboflow.com/docs/hand.jpg").content
image = cv2.imdecode(np.frombuffer(content, np.uint8), cv2.IMREAD_COLOR)

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/c244720ab40aafe6e7c322cd8fe5c12ec2d7999b" alt=""><figcaption></figcaption></figure>

## Roboflow 3.0 クラス分類

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

### コードサンプル

```python
import os
import cv2
import numpy as np
import requests
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)

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})")
```
