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

# Moondream2

Moondream2는 컴팩트한 비전-언어 모델입니다. Roboflow Inference에서는 오픈 보캐뷸러리 객체 탐지기로 제공됩니다. 프롬프트로 클래스 이름을 전달하면 일치하는 영역의 바운딩 박스를 받을 수 있습니다.

{% hint style="info" %}
Moondream2는 Serverless Cloud API에서 사용할 수 없습니다. 다음에서 실행하세요 [전용 배포](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments) 또는 [자체 호스팅 추론](https://docs.roboflow.com/deployment/self-hosted/self-hosted).
{% endhint %}

## Moondream2 API

{% stepper %}
{% step %}

### API 키 받기

Roboflow 계정을 만들고, [Roboflow API 설정 페이지](https://app.roboflow.com/settings/api) 에서 키를 찾아 셸에서 사용할 수 있게 하세요:

```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` 전용 배포 URL 또는 로컬 추론 서버에.

```python
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)
```

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

## Moondream2 추론 속도

다음을 사용하여 측정한 지연 시간 [Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) 1x NVIDIA L4, 배치 크기 1에서 이미지 한 장을 캡셔닝할 때의 속도입니다. Moondream2는 출력 길이를 고정할 수 없으므로 지연 시간은 응답에 따라 달라집니다.

<table data-search="false"><thead><tr><th>별칭</th><th>지연 시간(ms)</th></tr></thead><tbody><tr><td><code>moondream2</code></td><td>1669</td></tr></tbody></table>

{% hint style="info" %}
설정하세요 `api_url` 를 배포 대상에 맞게:

* `http://localhost:9001` 로컬 [Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) 서버용입니다.
* 귀하의 [전용 배포](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments) 는 비공개 엔드포인트의 URL입니다.
  {% endhint %}

## 자체 호스팅 Inference로 Moondream2 실행하기

Moondream2는 또한 직접 [`inference`](https://docs.roboflow.com/deployment/self-hosted/self-hosted) 패키지와 함께 로드할 수도 있습니다. 탐지 외에도 이 모델은 이미지 캡셔닝, 포인트 프롬프트 탐지, 시각적 질의응답을 지원합니다.

{% 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, "이 이미지에 개는 몇 마리 있나요?")

print(result)
```

{% endstep %}
{% endstepper %}

### Workflows의 실행 모드

다음에서 사용할 때 [Workflow](https://docs.roboflow.com/workflows), Moondream2는 두 가지 모드 중 하나로 실행됩니다:

* **로컬 실행**: 모델이 사용자의 Inference 서버에서 실행됩니다(GPU 권장).
* **원격 실행**: 모델이 원격 Inference 서버에서 HTTP로 다음을 통해 호출됩니다: `infer_lmm()` 클라이언트 메서드.
