For the complete documentation index, see llms.txt. This page is also available as Markdown.

Grounding DINO

Dedicated Deployment または self-hosted Inference で text-prompted object detection に Grounding DINO を使用します

Grounding DINO は、open-vocabulary の object detector です。画像と text classes のリストを渡すと、モデルは学習なしで一致する領域の bounding boxes を返します。

Grounding DINO は Serverless Hosted API では利用できません。次の環境で実行してください Dedicated Deployment または self-hosted Inference.

コードサンプル

1

API Key を取得する

Roboflow アカウントを作成し、キーを次の場所で見つけます Roboflow API 設定ページ そしてシェルで利用できるようにします:

export ROBOFLOW_API_KEY="your-key-here"
2

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

これらのパッケージは API を呼び出し、その結果を描画します:

pip install requests supervision opencv-python
3

モデルを実行する

設定する URL を Dedicated Deployment の URL またはローカルの Inference server に設定します。

import base64
import os
import cv2
import numpy as np
import requests
import supervision as sv

URL = "https://your-deployment.roboflow.cloud"
content = requests.get("https://media.roboflow.com/notebooks/examples/dog.jpeg").content
image = cv2.imdecode(np.frombuffer(content, np.uint8), cv2.IMREAD_COLOR)
_, buffer = cv2.imencode(".jpg", image)
image_base64 = base64.b64encode(buffer).decode("utf-8")

response = requests.post(
    f"{URL}/grounding_dino/infer",
    json={
        "api_key": os.environ["ROBOFLOW_API_KEY"],
        "image": {"type": "base64", "value": image_base64},
        "text": ["dog", "person", "backpack"],
    },
)
preds = response.json()["predictions"]

xyxys = [
    [p["x"] - p["width"] / 2, p["y"] - p["height"] / 2,
     p["x"] + p["width"] / 2, p["y"] + p["height"] / 2]
    for p in preds
]
detections = sv.Detections(
    xyxy=np.array(xyxys, dtype=float),
    class_id=np.array([p.get("class_id", 0) for p in preds]),
    confidence=np.array([p["confidence"] for p in preds], dtype=float),
    data={"class_name": np.array([p["class"] for p in preds])},
)
labels = [f"{p['class']} {p['confidence']:.2f}" for p in preds]
annotated = sv.BoxAnnotator().annotate(image.copy(), detections)
annotated = sv.LabelAnnotator().annotate(annotated, detections, labels=labels)
cv2.imwrite("dog_annotated.png", annotated)

推論速度

〜で測定されたレイテンシ Roboflow Inference 1x NVIDIA L4、バッチサイズ 1、ウォームアップ後の平均で測定。

モデル
レイテンシ (ms)

grounding-dino

165.4

2つの text prompts で測定しました。

設定する URL をデプロイ先に合わせてください:

  • http://localhost:9001 ローカルの Inference サーバー用。

  • あなたの Dedicated Deployment プライベートエンドポイントの URL。

最終更新

役に立ちましたか?