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

Moondream2

Dedicated Deployment または self-hosted Inference で open-vocabulary detection に Moondream2 を使用します

Moondream2 はコンパクトな vision-language model です。Roboflow Inference では、open-vocabulary object detector として公開されています。クラス名を prompt として渡すと、該当する領域の bounding boxes を受け取れます。

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

コードサンプル

1

API Key を取得する

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

export ROBOFLOW_API_KEY="your-key-here"
2

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

次をインストールします: Inference SDKsupervision:

pip install inference-sdk supervision opencv-python
3

モデルを実行する

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

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/notebooks/examples/dog.jpeg").content
image = cv2.imdecode(np.frombuffer(content, np.uint8), cv2.IMREAD_COLOR)
client = InferenceHTTPClient(
    api_url="https://your-deployment.roboflow.cloud",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)
result = client.infer_lmm(
    image,
    model_id="moondream2",
    prompt="dog",
)

preds = result["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.get("confidence", 1.0) for p in preds], dtype=float),
    data={"class_name": np.array([p["class"] for p in preds])},
)
labels = [f"{p['class']} {p.get('confidence', 1.0):.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 NVIDIA L4 1枚で、バッチサイズ1、1画像のcaptioningを行います。Moondream2 は出力長を固定できないため、レイテンシは応答によって変動します。

別名
レイテンシ (ms)

moondream2

1669

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

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

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

最終更新

役に立ちましたか?