> 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/roboflow/roboflow-hi/deploy/supported-models/owlv2.md).

# OwlV2

OwlV2 Google का open-vocabulary object detector है। आप reference image पर एक या अधिक example bounding boxes देते हैं, और OwlV2 बिना किसी training के target images में समान objects detect करता है।

{% hint style="info" %}
OwlV2 Serverless Hosted API पर उपलब्ध नहीं है। इसे एक पर चलाएँ [Dedicated Deployment](/roboflow/roboflow-hi/deploy/dedicated-deployments.md) या [self-hosted Inference](https://inference.roboflow.com/).
{% endhint %}

## कोड नमूना

{% stepper %}
{% step %}

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

एक Roboflow खाता बनाएं, अपनी key यहाँ पर ढूँढें [Roboflow API settings page](https://app.roboflow.com/settings/api) और इसे अपने shell में उपलब्ध कराएँ:

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

{% endstep %}

{% step %}

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

ये packages API को call करते हैं और इसके results को draw करते हैं:

```bash
pip install requests supervision opencv-python
```

{% endstep %}

{% step %}

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

नीचे दिया गया sample input image पर एक single example box को prompt के रूप में उपयोग करता है और उसी image में matching objects detect करता है। व्यवहार में आप आमतौर पर एक अलग reference image pass करते हैं। सेट करें `URL` को अपने Dedicated Deployment URL या local Inference server पर।

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

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

## Inference speed

Latency मापी गई [Roboflow Inference](https://inference.roboflow.com/) 1x NVIDIA L4 पर, batch size 1, warmup के बाद का औसत।

<table data-search="false"><thead><tr><th>मॉडल</th><th>विलंबता (ms)</th></tr></thead><tbody><tr><td><code>owlv2</code></td><td>541.2</td></tr></tbody></table>

पर मापा गया `owlv2-large-patch14-ensemble` checkpoint के साथ दो text prompts पर।

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

* `http://localhost:9001` एक local [Inference](https://inference.roboflow.com/) server.
* आपका [Dedicated Deployment](/roboflow/roboflow-hi/deploy/dedicated-deployments.md) एक private endpoint के लिए URL.
  {% endhint %}

OwlV2 confidences आमतौर पर बहुत उच्च होती हैं (0.99 से ऊपर)। `confidence` parameter को उसी अनुसार tune करें।
