> 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/perception-encoder.md).

# Perception Encoder

Perception Encoder Meta का vision-language embedding मॉडल है। यह similarity search, zero-shot classification, और retrieval के लिए images और text को एक shared embedding space में map करता है।

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

हम तीन Perception Encoder endpoints का समर्थन करते हैं:

* `/perception_encoder/embed_image` - एक image embed करें
* `/perception_encoder/embed_text` - एक string embed करें
* `/perception_encoder/compare` - एक image और text prompts की सूची के बीच similarity की गणना करें

## Perception Encoder API

{% stepper %}
{% step %}

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

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

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

{% endstep %}

{% step %}

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

ये packages image fetch करते हैं और API call करते हैं:

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

{% endstep %}

{% step %}

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

नीचे दिया गया sample एक image को भेजता है `/perception_encoder/embed_image` और embedding shape को print करता है। सेट करें `URL` अपने समर्पित डिप्लॉयमेंट URL या एक स्थानीय इन्फ़रेंस सर्वर पर।

```python
import base64
import os
import cv2
import requests
import supervision as sv

URL = "https://your-deployment.roboflow.cloud"

image = sv.load_image_from_url("https://media.roboflow.com/notebooks/examples/dog.jpeg")

_, buffer = cv2.imencode(".jpg", image)
image_base64 = base64.b64encode(buffer).decode("utf-8")

response = requests.post(
    f"{URL}/perception_encoder/embed_image",
    headers={"Authorization": f"Bearer {os.environ['ROBOFLOW_API_KEY']}"},
    json={
        "image": {"type": "base64", "value": image_base64},
    },
)
result = response.json()
embedding = result["embeddings"][0]
print(f"Embedding length: {len(embedding)}")
print(f"पहले मान: {embedding[:5]}")
```

{% endstep %}
{% endstepper %}

ऊपर दिया गया code terminal पर embedding shape print करता है:

```
Embedding length: 1024
First values: [0.0545, -0.0338, -0.0355, -0.0062, 0.0154]
```

## Perception Encoder अनुमान गति

लेटेंसी मापी गई [Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) 1x NVIDIA L4 पर, बैच आकार 1 के साथ, वार्मअप के बाद औसत।

<table data-search="false"><thead><tr><th>मॉडल</th><th>लेटेंसी (ms)</th></tr></thead><tbody><tr><td><code>perception-encoder</code></td><td>25.2</td></tr></tbody></table>

के साथ मापा गया `embed_image` पर `PE-Core-L14-336` चेकपॉइंट (केवल इमेज एम्बेडिंग)।

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

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

## Self-hosted Inference के साथ Perception Encoder चलाएँ

Perception Encoder को सीधे [`inference`](https://docs.roboflow.com/deployment/self-hosted/self-hosted) package के साथ लोड किया जा सकता है, जो स्थानीय रूप से कई images या video frames को embed करने के लिए सबसे तेज़ तरीका है।

{% stepper %}
{% step %}

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

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

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

{% step %}

### स्थानीय रूप से एम्बेड और तुलना करें

```python
from inference.core.utils.postprocess import cosine_similarity
from inference.models import PerceptionEncoder

pe = PerceptionEncoder(model_id="perception_encoder/PE-Core-B16-224")

image_embedding = pe.embed_image("https://media.roboflow.com/inference/people-walking.jpg")
text_embedding = pe.embed_text("a crowd of people walking")

print(cosine_similarity(image_embedding[0], text_embedding[0]))
```

{% endstep %}
{% endstepper %}

### उपलब्ध चेकपॉइंट्स

`model_id` backbone चुनता है:

* `perception_encoder/PE-Core-B16-224`
* `perception_encoder/PE-Core-L14-336`
* `perception_encoder/PE-Core-G14-448`

केवल CLIP-शैली interface समर्थित है; language-aligned और spatially-aligned Perception Encoder variants अभी उपलब्ध नहीं हैं।

{% hint style="info" %}
Perception Encoder वही API shape उपयोग करता है जो [CLIP](/models/hi/supported-models/clip.md): `embed_image`, `embed_text`, और `compare` करता है; वही arguments लेता है और वही response format लौटाता है, इसलिए CLIP के लिए लिखा गया code model बदलकर Perception Encoder के साथ काम करता है।
{% endhint %}

### Workflows में उपयोग करें

Perception Encoder उपलब्ध है [Workflows](https://docs.roboflow.com/workflows) के माध्यम से **Perception Encoder Embedding Model** block, जो code लिखे बिना image या text embeddings उत्पन्न करता है।
