> 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/reference/hi/inference/inference-python.md).

# Inference Python Package

यह `inference` Python पैकेज वह मुख्य ओपन सोर्स लाइब्रेरी है जो Roboflow के कंप्यूटर विज़न डिप्लॉयमेंट स्टैक को शक्ति देती है। यह मॉडल लोडिंग, प्री/पोस्ट-प्रोसेसिंग, GPU/CPU अनुकूलन, और [वर्कफ़्लोज़](https://docs.roboflow.com/workflows) निष्पादन, जिसे सीधे Python से कॉल किया जा सकता है।

यह [Inference Server](https://docs.roboflow.com/deployment/self-hosted/inference-server) इस पैकेज को रैप करता है और इसे HTTP के माध्यम से उपलब्ध कराता है (सभी निर्भरताएँ इंस्टॉल की हुई Docker image के रूप में वितरित), लेकिन आप इसे भी उपयोग कर सकते हैं `inference` अपने स्वयं के स्क्रिप्ट्स और अनुप्रयोगों में सीधे।

## घटक कैसे एक साथ फिट होते हैं

Inference में कई घटक हैं जो मिलकर कंप्यूटर विज़न मॉडलों को सर्व करते हैं:

* [**inference**](/reference/hi/inference/inference-python.md) - मॉडल लोडिंग, inference, और Workflows निष्पादन के लिए मुख्य Python पैकेज।
* [**inference-sdk**](/reference/hi/inference/inference-sdk.md) - HTTP के माध्यम से Inference Server के साथ संचार करने के लिए हल्का Python क्लाइंट।
* [**inference-cli**](/reference/hi/inference/inference-cli.md) - Inference Server को प्रबंधित करने और सामान्य कार्य चलाने के लिए कमांड-लाइन टूल।
* [**Inference Server**](https://docs.roboflow.com/deployment/self-hosted/inference-server) - HTTP सर्वर (Docker) जो `inference` पैकेज को REST API के रूप में।

रनटाइम पर ये घटक कैसे व्यवहार करते हैं (अनुरोध रूटिंग, समानांतरकरण, माइक्रोसर्विस और एप्लायंस पैटर्न), इसके लिए देखें [Inference Architecture](https://docs.roboflow.com/deployment/self-hosted/inference-server/architecture).

## बहु-बैकएंड समर्थन

Inference 1.0 कई inference runtime backends का समर्थन करता है: ONNX, TensorRT, Hugging Face, और PyTorch. यह आपके हार्डवेयर के लिए उपलब्ध सबसे तेज़ backend को स्वचालित रूप से चुनता है। उदाहरण के लिए, यदि आपके पास NVIDIA GPU है या आप Jetson डिवाइस पर चल रहे हैं और आपके प्लेटफ़ॉर्म पर मॉडल के लिए TensorRT engine उपलब्ध है, तो Inference डिफ़ॉल्ट रूप से TensorRT का उपयोग करता है।

## इंस्टॉलेशन

हम उपयोग करने की अनुशंसा करते हैं [Python virtual environment (venv)](https://docs.python.org/3/tutorial/venv.html) Inference की निर्भरताओं को अलग रखने के लिए।

pip के माध्यम से Inference इंस्टॉल करने के लिए:

```bash
pip install inference
```

यदि आपके पास NVIDIA GPU है, तो आप अपने inference को इससे तेज़ कर सकते हैं:

```bash
pip install --extra-index-url https://download.pytorch.org/whl/cu124 inference-gpu
# कृपया --extra-index-url को आपके OS में इंस्टॉल किए गए CUDA संस्करण के अनुसार समायोजित करें
# https://download.pytorch.org/whl/cu<major><minor>, उदाहरण के लिए CUDA 13.0 के लिए https://download.pytorch.org/whl/cu130
```

## त्वरित उदाहरण

आप inference को या तो HTTP के माध्यम से Inference Server के विरुद्ध चला सकते हैं (के साथ `inference-sdk`) या सीधे अपने प्रक्रिया में (मूल `inference` पैकेज)। मूल `get_model()` कॉल मॉडल को आपके स्क्रिप्ट में लोड करता है और एक ऑब्जेक्ट लौटाता है जिसे आप कॉल कर सकते हैं `.infer()` उस पर; HTTP क्लाइंट इमेज को एक सर्वर पर भेजता है जो वही काम करता है।

{% tabs %}
{% tab title="इन्फरेंस (मूल)" %}

```python
from inference import get_model

model = get_model(model_id="rfdetr-small")
results = model.infer("https://media.roboflow.com/inference/people-walking.jpg")
```

{% endtab %}

{% tab title="inference-sdk (HTTP क्लाइंट)" %}

```python
from inference_sdk import InferenceHTTPClient, InferenceConfiguration

client = InferenceHTTPClient(
    # api_url="http://localhost:9001",  # self-hosted के लिए
    api_url="https://serverless.roboflow.com",
    api_key="ROBOFLOW_API_KEY",
).configure(InferenceConfiguration(api_key_transport="header"))
results = client.infer(
    "https://media.roboflow.com/inference/people-walking.jpg",
    model_id="rfdetr-small",
)
```

{% endtab %}
{% endtabs %}

API key की आवश्यकता वाले मॉडलों का उपयोग करने के लिए, सेट करें `ROBOFLOW_API_KEY` environment variable या इसे सीधे पास करें:

```python
model = get_model(model_id="my-project/1", api_key="ROBOFLOW_API_KEY")
```

देखें [मूल Python API](/reference/hi/inference/inference-python/native-python-api.md) दृश्यांकन के साथ अधिक विस्तृत चरण-दर-चरण मार्गदर्शन के लिए पृष्ठ देखें, और [एक मॉडल चलाएँ](https://docs.roboflow.com/deployment/self-hosted/self-hosted#run-a-model) सर्वर-आधारित पथ के लिए।

## Inference पाइपलाइन

`InferencePipeline` वीडियो को उसी Python प्रक्रिया के भीतर चलाता है जैसे `inference` पैकेज। इसका उपयोग केवल तब करें जब आप सीधे Inference Library निष्पादन चुनते हैं और इसकी कस्टम लॉजिक या sink interfaces तक पहुँच की आवश्यकता होती है। जो अनुप्रयोग Inference Server या Serverless का उपयोग करते हैं, उन्हें उपयोग करना चाहिए [WebRTC Streaming](/reference/hi/inference/inference-sdk/webrtc.md).

```python
from inference import InferencePipeline
from inference.core.interfaces.stream.sinks import render_boxes

pipeline = InferencePipeline.init(
    model_id="rfdetr-large",
    video_reference="https://storage.googleapis.com/com-roboflow-marketing/inference/people-walking.mp4",
    on_prediction=render_boxes,
    api_key="ROBOFLOW_API_KEY",
)

pipeline.start()
pipeline.join()
```

ऊपर दिया गया कोड ऑब्जेक्ट डिटेक्शन एनोटेशन सीधे करता है (के माध्यम से `render_boxes` sink)। अधिक जानकारी के लिए, देखें [Inference पाइपलाइन](/reference/hi/inference/inference-python/inference-pipeline.md) पृष्ठ।

## योगदान

Inference ओपन सोर्स है। सोर्स कोड, issue tracker, और योगदान मार्गदर्शिका इसमें स्थित हैं [roboflow/inference](https://github.com/roboflow/inference) repository; देखें [CONTRIBUTING.md](https://github.com/roboflow/inference/blob/main/CONTRIBUTING.md) शुरू करने के लिए।

## अगले चरण

* [मूल Python API](/reference/hi/inference/inference-python/native-python-api.md) - मॉडल लोड करें और अपने स्वयं के प्रक्रिया में inference चलाएँ।
* [Inference पाइपलाइन](/reference/hi/inference/inference-python/inference-pipeline.md) - वीडियो स्ट्रीम्स पर मॉडल चलाएँ।
* [मॉडल वेट्स डाउनलोड](/reference/hi/inference/inference-python/offline-weights.md) - वेट कैशिंग और स्थायी भंडारण।
* [बेंचमार्क](/reference/hi/inference/inference-python/benchmarks.md) - सामान्य हार्डवेयर पर मापा गया थ्रूपुट।
