Moondream2
Run the Moondream2 open-vocabulary detection API on a Dedicated Deployment or self-hosted Inference
Moondream2 is a compact vision-language model. In Roboflow Inference, it is exposed as an open-vocabulary object detector: pass a class name as the prompt and receive bounding boxes for matching regions.
Moondream2 API
Get your API Key
Create a Roboflow account, find your key on the Roboflow API settings page and make it available to your shell:
export ROBOFLOW_API_KEY="your-key-here"Install the dependencies
Install the Inference SDK and supervision:
pip install -U inference-sdk supervision opencv-pythonRun the model
Set api_url to your Dedicated Deployment URL or a local Inference server.
import os
import cv2
import numpy as np
import supervision as sv
from inference_sdk import InferenceHTTPClient, InferenceConfiguration
image = sv.load_image_from_url("https://media.roboflow.com/notebooks/examples/dog.jpeg")
client = InferenceHTTPClient(
api_url="https://your-deployment.roboflow.cloud",
api_key=os.environ["ROBOFLOW_API_KEY"],
).configure(InferenceConfiguration(api_key_transport="header"))
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)
Moondream2 inference speed
Latency measured with Roboflow Inference on 1x NVIDIA L4, batch size 1, captioning one image. Moondream2 cannot fix its output length, so latency varies with the response.
moondream2
1669
Run Moondream2 with self-hosted Inference
Moondream2 can also be loaded directly with the inference package. Beyond detection, the model supports image captioning, point-prompt detection, and visual question answering.
Execution modes in Workflows
When used in a Workflow, Moondream2 runs in one of two modes:
Local execution: the model runs on your Inference server (GPU recommended).
Remote execution: the model is invoked over HTTP on a remote Inference server through the
infer_lmm()client method.
Last updated
Was this helpful?