For the complete documentation index, see llms.txt. This page is also available as Markdown.

नेटिव Python API

get_model के साथ एक मॉडल लोड करें, अपनी खुद की Python प्रक्रिया में छवियों पर inference चलाएँ, और supervision के साथ परिणामों को विज़ुअलाइज़ करें।

नेटिव 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) का उपयोग करें ताकि Inference की dependencies को अलग रखा जा सके।

pip install inference

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

pip install --extra-index-url https://download.pytorch.org/whl/cu124 inference-gpu
# कृपया --extra-index-url को अपने OS में स्थापित CUDA version के अनुसार समायोजित करें

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

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}".

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

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। इसमें कुछ metadata (जैसे processing time) के साथ-साथ predictions की एक array भी होती है। response का प्रकार और उसके attributes model के प्रकार पर निर्भर करते हैं।

अब, चलिए results को Supervision:

annotated लोगों की चाल

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

यह infer(...) method कई रूपों में images स्वीकार करती है, जिनमें PIL images, OpenCV images (NumPy arrays), स्थानीय images के paths, image URLs, और बहुत कुछ शामिल हैं। अंदरूनी रूप से, models load_image(...) method का उपयोग image_utils module में करती हैं.

Inference parameters

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

अगले चरण

अंतिम अपडेट

क्या यह उपयोगी था?