> 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/florence-2.md).

# Florence 2

हम समर्थन करते हैं [Microsoft का Florence 2](https://huggingface.co/microsoft/Florence-2-base), एक मल्टीमोडल विज़न-लैंग्वेज मॉडल, हमारे [Serverless Hosted API](/roboflow/roboflow-hi/deploy/serverless-hosted-api-v2.md). Florence 2 captioning, object detection, segmentation, और OCR को task prompts (जैसे `<CAPTION>`, `<OD>`, `<OCR>`, `<REFERRING_EXPRESSION_SEGMENTATION>`).

## डिफ़ॉल्ट उपनाम

उपनाम को `model_id` के रूप में अपने अनुरोध में उपयोग करें और runtime इसे संबंधित pretrained weights में resolve कर देता है।

<table data-search="false"><thead><tr><th>उपनाम</th></tr></thead><tbody><tr><td><code>florence-2-base</code></td></tr><tr><td><code>florence-2-large</code></td></tr></tbody></table>

## सटीकता

आधिकारिक model cards से प्रमुख zero-shot मेट्रिक्स ([base](https://huggingface.co/microsoft/Florence-2-base), [large](https://huggingface.co/microsoft/Florence-2-large)):

<table data-header-hidden data-search="false"><thead><tr><th></th><th></th><th></th></tr></thead><tbody><tr><td>बेंचमार्क</td><td><code>florence-2-base</code></td><td><code>florence-2-large</code></td></tr><tr><td>COCO Caption (CIDEr)</td><td>133.0</td><td>135.6</td></tr><tr><td>COCO detection (mAP)</td><td>34.7</td><td>37.5</td></tr><tr><td>RefCOCO (accuracy)</td><td>53.9</td><td>56.3</td></tr></tbody></table>

## Inference speed

Latency मापी गई [Roboflow Inference](https://inference.roboflow.com/) 1x NVIDIA L4 पर, batch size 1 के साथ, और `<CAPTION>` prompt से greedy decoding का उपयोग करके ठीक 128 tokens generate करते हुए। Latency आउटपुट लंबाई के साथ scale होती है, इसलिए अन्य लंबाइयों का अनुमान लगाने के लिए tokens/sec का उपयोग करें।

<table data-search="false"><thead><tr><th>उपनाम</th><th>विलंबता, 128 tokens (ms)</th><th>टोकन/सेकंड</th></tr></thead><tbody><tr><td><code>florence-2-base</code></td><td>652</td><td>198</td></tr><tr><td><code>florence-2-large</code></td><td>1120</td><td>115</td></tr></tbody></table>

## कोड नमूना

Florence 2 साझा `/infer/lmm` endpoint के माध्यम से चलता है। इसे सीधे HTTP endpoint के जरिए `curl`, या [`inference-sdk`](https://inference.roboflow.com/inference_helpers/inference_sdk/) रैपर के साथ।

{% tabs %}
{% tab title="HTTP (curl)" icon="webhook" %}
{% 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 %}

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

को कॉल करें `/infer/lmm` endpoint को `curl`:

```bash
curl --location 'https://serverless.roboflow.com/infer/lmm' \
  --header 'Content-Type: application/json' \
  --data '{
    \"api_key\": \"'\"$ROBOFLOW_API_KEY\"'\",
    "image": {"type": "url", "value": "https://media.roboflow.com/quickstart/dog.jpeg"},
    "model_id": "florence-2-base",
    "prompt": "<CAPTION>"
  }'
```

{% endstep %}
{% endstepper %}
{% endtab %}

{% tab title="SDK (Python)" icon="python" %}
{% 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 %}

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

यह पैकेज मॉडल को कॉल करता है:

```bash
pip install inference-sdk
```

{% endstep %}

{% step %}

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

LMM inference endpoint को एक task prompt के साथ कॉल करें:

```python
import os
import cv2
import numpy as np
import requests
from inference_sdk import InferenceHTTPClient

content = requests.get("https://media.roboflow.com/quickstart/dog.jpeg").content
image = cv2.imdecode(np.frombuffer(content, np.uint8), cv2.IMREAD_COLOR)

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)

result = client.infer_lmm(
    inference_input=image,
    model_id="florence-2-base",
    prompt="<CAPTION>",
)

print(result["response"])  # {'<CAPTION>': 'पीठ पर कुत्ता लिए एक आदमी.'}
```

<figure><img src="/files/601adb5155c3b69178d4b7597937aec79be30313" alt=""><figcaption></figcaption></figure>
{% endstep %}
{% endstepper %}
{% endtab %}
{% endtabs %}

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

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

स्वैप करें `<CAPTION>` को किसी भी समर्थित task prompt से (उदाहरण के लिए `<DETAILED_CAPTION>`, `<OD>`, `<OCR>`, `<OPEN_VOCABULARY_DETECTION>`, `<REFERRING_EXPRESSION_SEGMENTATION>`) ताकि captioning, detection, OCR, और segmentation tasks के बीच स्विच किया जा सके।

स्व-होस्टेड deployment और task prompts की पूरी सूची के लिए, देखें [Inference documentation](https://inference.roboflow.com/).
