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

OwlV2

Dedicated Deployment または self-hosted Inference で one-shot object detection に OwlV2 を使用します

OwlV2 は Google の open-vocabulary object detector です。参照画像に 1 つ以上の例となる bounding box を指定すると、OwlV2 は追加の学習なしでターゲット画像内の類似オブジェクトを検出します。

OwlV2 は 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

モデルを実行する

以下のサンプルでは、入力画像上の 1 つの例の box をプロンプトとして使用し、同じ画像内の一致するオブジェクトを検出します。実際には、通常は別の参照画像を渡します。 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}/owlv2/infer",
    json={
        "api_key": os.environ["ROBOFLOW_API_KEY"],
        "image": {"type": "base64", "value": image_base64},
        "training_data": [{
            "image": {"type": "base64", "value": image_base64},
            "boxes": [{"x": 360, "y": 800, "w": 500, "h": 500, "cls": "dog"}],
        }],
        "confidence": 0.99,
    },
)
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)

owlv2

541.2

で測定 owlv2-large-patch14-ensemble チェックポイントを、2 つの text prompt で。

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

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

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

OwlV2 の confidence は通常非常に高くなります(0.99 を超えることが多いです)。 confidence parameter をそれに応じて調整してください。

最終更新

役に立ちましたか?