> 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/models/hi/supported-models/moondream2.md).

# Moondream2

Moondream2 एक कॉम्पैक्ट विज़न-लैंग्वेज मॉडल है। Roboflow Inference में, इसे एक open-vocabulary object detector के रूप में उपलब्ध कराया जाता है: प्रॉम्प्ट के रूप में एक class name दें और matching regions के लिए bounding boxes प्राप्त करें।

{% hint style="info" %}
Moondream2 Serverless Hosted API पर उपलब्ध नहीं है। इसे एक [समर्पित परिनियोजन](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments) या [स्व-होस्टेड इनफ़रेंस](https://docs.roboflow.com/deployment/self-hosted/self-hosted).
{% endhint %}

## कोड नमूना

{% stepper %}
{% step %}

### अपनी API कुंजी प्राप्त करें

एक Roboflow खाता बनाएँ, अपनी कुंजी यहाँ खोजें [Roboflow API सेटिंग्स पेज](https://app.roboflow.com/settings/api) और इसे अपने shell के लिए उपलब्ध कराएँ:

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

{% endstep %}

{% step %}

### निर्भरताएँ इंस्टॉल करें

इंस्टॉल करें [Inference SDK](https://docs.roboflow.com/deployment/self-hosted/self-hosted) और [supervision](https://supervision.roboflow.com/):

```bash
pip install -U inference-sdk supervision opencv-python
```

{% endstep %}

{% step %}

### मॉडल चलाएँ

सेट करें `api_url` अपने Dedicated Deployment URL या किसी स्थानीय Inference सर्वर पर।

```python
import os
import cv2
import numpy as np
import supervision as sv
from inference_sdk import InferenceHTTPClient

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"],
)
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)
```

<figure><img src="/files/185397761163a5fe2455a36d02ce9fd639841b4b" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}

## इनफ़रेंस गति

विलंबता मापी गई [Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) 1x NVIDIA L4 पर, batch size 1, एक image का captioning करते समय। Moondream2 अपने output length को निश्चित नहीं कर सकता, इसलिए latency response के साथ बदलती है।

<table data-search="false"><thead><tr><th>उपनाम</th><th>Latency (ms)</th></tr></thead><tbody><tr><td><code>moondream2</code></td><td>1669</td></tr></tbody></table>

{% hint style="info" %}
सेट करें `api_url` को अपने deployment target से मिलाने के लिए:

* `http://localhost:9001` एक स्थानीय [Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) server के लिए।
* आपका [समर्पित परिनियोजन](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments) एक निजी endpoint के लिए URL।
  {% endhint %}

## Inference (self-hosted) के साथ उपयोग करें

Moondream2 को सीधे भी लोड किया जा सकता है [`इनफ़रेंस`](https://docs.roboflow.com/deployment/self-hosted/self-hosted) पैकेज। detection के अलावा, यह मॉडल image captioning, point-prompt detection, और visual question answering का समर्थन करता है।

{% stepper %}
{% step %}

### पैकेज इंस्टॉल करें

```bash
pip install "inference[transformers]"
```

उपयोग करें `inference-gpu[transformers]` एक GPU मशीन पर।
{% endstep %}

{% step %}

### मॉडल चलाएँ

```python
from PIL import Image

from inference.models.moondream2.moondream2 import Moondream2

model = Moondream2(api_key="YOUR_API_KEY")

image = Image.open("dog.jpeg")
result = model.query(image, "How many dogs are in this image?")

print(result)
```

{% endstep %}
{% endstepper %}

### वर्कफ़्लोज़ में निष्पादन मोड

जब इसे एक में उपयोग किया जाता है [वर्कफ़्लो](https://docs.roboflow.com/workflows), Moondream2 दो में से किसी एक मोड में चलता है:

* **लोकल निष्पादन**: मॉडल आपके Inference सर्वर पर चलता है (GPU अनुशंसित)।
* **रिमोट निष्पादन**: मॉडल को एक रिमोट Inference सर्वर पर HTTP के माध्यम से `infer_lmm()` क्लाइंट विधि।
