> 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/native-python-api.md).

# मूल Python API

नेटिव Python API, Inference का उपयोग करने का सबसे सरल तरीका है और इसमें base package APIs तक सीधे पहुंच शामिल होती है। इस तरीके से, आप Inference modules को सीधे अपने Python कोड में import करते हैं। आप models को load करते हैं, inference चलाते हैं, और results को अपनी ही logic के भीतर संभालते हैं। आप अपने Python environment के भीतर dependencies भी manage करते हैं। यदि आप एक simple app बना रहे हैं या सिर्फ testing कर रहे हैं, तो native Python API शुरू करने के लिए एक बेहतरीन जगह है।

नेटिव Python API का उपयोग मुख्य रूप से models को load करने, फिर उनके `infer(...)` method को कॉल करके inference results प्राप्त करने पर केंद्रित है।

## त्वरित प्रारंभ

यह उदाहरण दिखाता है कि कैसे एक model load करें, inference चलाएं, फिर results प्रदर्शित करें।

हम सलाह देते हैं कि आप [Python virtual environment (venv)](https://docs.python.org/3/tutorial/venv.html) का उपयोग करें ताकि Inference की dependencies को अलग रखा जा सके।

```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 version के अनुसार समायोजित करें
```

इसके बाद, एक model import करें:

```python
from inference import get_model

model = get_model(model_id="rfdetr-large")
```

यह `get_model` method एक utility function है जो Roboflow से एक computer vision model load करती है। हम model को उसके संदर्भ से load करते हैं `model_id`. Roboflow models के लिए, model ID एक project name और version number का संयोजन होता है: `f"{project_name}/{version_number}"`.

{% hint style="success" %}
आप अपने model का project name और version number [Roboflow ऐप](/reference/hi/authentication/authentication/workspace-and-project-ids.md)में पा सकते हैं। आप सार्वजनिक models भी ब्राउज़ कर सकते हैं जो [Roboflow Universe](https://universe.roboflow.com/). में उपयोग के लिए तैयार हैं। इस उदाहरण में, हम एक विशेष model ID का उपयोग कर रहे हैं जो COCO pre-trained model का एक alias है। देखें [pre-trained model aliases](https://docs.roboflow.com/models/pretrained-aliases) की सूची के लिए aliases.
{% endhint %}

इसके बाद, हम input image प्रदान करके अपने model के साथ inference चला सकते हैं:

```python
from inference import get_model

model = get_model(model_id="rfdetr-large")

results = model.infer("people-walking.jpg") # अपनी image के path से बदलें
```

results object एक inference response object है (उदाहरण के लिए `ObjectDetectionInferenceResponse`, जो इसमें परिभाषित है [`inference/core/entities/responses/inference.py`](https://github.com/roboflow/inference/blob/main/inference/core/entities/responses/inference.py)। इसमें कुछ metadata (जैसे processing time) के साथ-साथ predictions की एक array भी होती है। response का प्रकार और उसके attributes model के प्रकार पर निर्भर करते हैं।

अब, चलिए results को [Supervision](https://supervision.roboflow.com):

```python
from inference import get_model
का उपयोग करके visualize करते हैं
import cv2

# model load करें
model = get_model(model_id="rfdetr-large")

# cv2 के साथ image load करें
image = cv2.imread("people-walking.jpg")

# inference चलाएं
results = model.infer(image)[0]

# results को Supervision Detection API में load करें
detections = sv.Detections.from_inference(results)

# Supervision annotators बनाएं
bounding_box_annotator = sv.BoxAnnotator()
label_annotator = sv.LabelAnnotator()

# inference results से labels array निकालें
labels = [p.class_name for p in results.predictions]

# Supervision annotators का उपयोग करके image पर results लागू करें
annotated_image = bounding_box_annotator.annotate(scene=image, detections=detections)
annotated_image = label_annotator.annotate(
    scene=annotated_image, detections=detections, labels=labels
)

# annotated image को file में लिखें या image प्रदर्शित करें
sv.plot_image(annotated_image)
```

<img src="https://storage.googleapis.com/com-roboflow-marketing/inference/people-walking-annotated.jpg" alt="annotated लोगों की चाल" width="100%">

## विभिन्न image प्रकार

यह `infer(...)` method कई रूपों में images स्वीकार करती है, जिनमें PIL images, OpenCV images (NumPy arrays), स्थानीय images के paths, image URLs, और बहुत कुछ शामिल हैं। अंदरूनी रूप से, models `load_image(...)` method का उपयोग [`image_utils` module में करती हैं](https://github.com/roboflow/inference/blob/main/inference/core/utils/image_utils.py).

```python
from inference import get_model

import cv2
from PIL import Image

model = get_model(model_id="rfdetr-large")

image_url = "https://media.roboflow.com/inference/people-walking.jpg"
local_image_file = "people-walking.jpg"
pil_image = Image.open(local_image_file)
numpy_image = cv2.imread(local_image_file)

results = model.infer(image_url)
#या     = model.infer(local_image_file)
#या     = model.infer(pil_image)
#या     = model.infer(numpy_image)
```

## Inference parameters

यह `infer(...)` method inference parameters सेट करने के लिए keyword arguments स्वीकार करती है। नीचे दिया गया उदाहरण confidence threshold और IoU threshold सेट करना दिखाता है।

```python
from inference import get_model

model = get_model(model_id="rfdetr-large")

results = model.infer("people-walking.jpg", confidence=0.75, iou_threshold=0.5)
```

## अगले चरण

* [Inference Pipeline](/reference/hi/inference/inference-python/inference-pipeline.md) - वीडियो streams पर वही models चलाएं।
* [Model Weights Download](/reference/hi/inference/inference-python/offline-weights.md) - control करें कि weights कहाँ cache किए जाएँ।
