> 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/sdks/web-browser/web-inference.js/inferencejs-reference.md).

# inferencejs संदर्भ

{% hint style="info" %}
के बारे में अधिक जानें `inferencejs` , हमारा web SDK, [यहाँ](/roboflow/roboflow-hi/deploy/sdks/web-browser.md)
{% endhint %}

### Installation

यह library browser के अंदर उपयोग के लिए डिज़ाइन की गई है, जिसमें vite, webpack, parcel आदि जैसे bundler का उपयोग किया जाता है। मान लेते हैं कि आपका bundler सेट अप है, तो आप इसे यह चलाकर install कर सकते हैं:

`npm install inferencejs`

### शुरू करना

शुरुआत करें `InferenceEngine`. यह एक background worker शुरू करेगा जो user interface को block किए बिना models को download और execute कर सकता है.

```typescript
import { InferenceEngine } from "inferencejs";

const PUBLISHABLE_KEY = "rf_a6cd..."; // Roboflow से अपनी publishable key से बदलें

const inferEngine = new InferenceEngine();

// मॉडल के model id से उसे load करें, जो Roboflow पर model के page से copy किया गया है.
const workerId = await inferEngine.startWorkerByModelId("[MODEL ID]", PUBLISHABLE_KEY);

// model पर inference चलाएँ
const result = await inferEngine.infer(workerId, img);
```

Model id model के page पर दिखाया जाता है और इसका रूप यह होता है `workspace/model-slug` (उदा.: `my-workspace/hard-hat-abc-1-yolov8n-t1`). Legacy project-versioned models को इसके साथ load किया जा सकता है `startWorker` project slug और version number का उपयोग करके। कई trained models वाले version के लिए, legacy `{project}/{version}` id, जब alias मौजूद हो, version के alias के माध्यम से resolve होता है; alias न होने पर यह केवल तभी काम करता है जब version में एक ही model हो, अन्यथा id ambiguous होती है और आपको model को उसके अपने model id से load करना चाहिए। देखें [legacy IDs कैसे resolve होते हैं](/roboflow/roboflow-hi/train/model-ids.md).

## API

### InferenceEngine

**`new InferenceEngine()`**

एक नया InferenceEngine instance बनाता है.

**`startWorkerByModelId(modelId: string, publishableKey: string): Promise<number>`**

दिए गए model id के लिए एक नया worker शुरू करता है और लौटाता है `workerId`. मॉडल लोड करने का यह अनुशंसित तरीका है. `modelId` पूरा `workspace/model-slug` id model के page पर दिखाया जाता है, और versionless तथा multi-model versions के लिए काम करता है. `publishableKey` आवश्यक है और इसे Roboflow में आपके project settings folder से प्राप्त किया जा सकता है.

**`startWorker(modelName: string, modelVersion: number, publishableKey: string): Promise<number>`**

project url slug और integer version द्वारा संबोधित legacy model को load करता है, और लौटाता है `workerId`. उपयोग करें `startWorkerByModelId` new integrations के लिए. `publishableKey` आवश्यक है और इसे Roboflow में आपके project settings folder से प्राप्त किया जा सकता है.

**`infer(workerId: number, img: CVImage | ImageBitmap): Promise<Inference>`**

दिए गए `workerId`. `img` का उपयोग करके worker के साथ किसी image पर inference करें `new CVImage(HTMLImageElement | HTMLVideoElement | ImageBitmap | TFJS.Tensor)` या [`createImageBitmap`](https://developer.mozilla.org/en-US/docs/Web/API/createImageBitmap)

**`stopWorker(workerId: number): Promise<void>`**

दिए गए `workerId`.

### `YOLO Lite` `YOLOv8` `YOLOv5`

का उपयोग करके inference करने का परिणाम `InferenceEngine` एक YOLO Lite, YOLOv8, या YOLOv5 object detection model पर यह निम्न प्रकार की array होती है:

```typescript
type RFObjectDetectionPrediction = {
    class?: string;
    confidence?: number;
    bbox?: {
        x: number;
        y: number;
        width: number;
        height: number;
    };
    color?: string;
};
```

### `GazeDetections`

का उपयोग करके inference करने का परिणाम `InferenceEngine` एक Gaze model पर। निम्न प्रकार की array:

```typescript
type GazeDetections = {
    leftEye: { x: number; y: number };
    rightEye: { x: number; y: number };
    yaw: number;
    pitch: number;
}[];
```

**`leftEye.x`**

leftEye की x स्थिति 0 और 1 के बीच एक floating point number के रूप में, input image की width के प्रतिशत में मापी गई।

**`leftEye.y`**

leftEye की y स्थिति 0 और 1 के बीच एक floating point number के रूप में, input image की height के प्रतिशत में मापी गई।

**`rightEye.x`**

rightEye की x स्थिति 0 और 1 के बीच एक floating point number के रूप में, input image की width के प्रतिशत में मापी गई।

**`rightEye.y`**

rightEye की y स्थिति 0 और 1 के बीच एक floating point number के रूप में, input image की height के प्रतिशत में मापी गई।

**`yaw`**

visual gaze का yaw, radians में मापा गया।

**`pitch`**

visual gaze का pitch, radians में मापा गया।

### `CVImage`

computer vision कार्यों के लिए उपयोग की जा सकने वाली image को दर्शाने वाली एक class. यह image को manipulate और convert करने के लिए विभिन्न methods प्रदान करती है.

#### **Constructor**

यह `CVImage(image)` class constructor class का एक नया instance initialize करता है. यह निम्न प्रकारों में से एक image स्वीकार करता है:

* `ImageBitmap`: एक वैकल्पिक `ImageBitmap` image का representation.
* `HTMLImageElement`: एक वैकल्पिक `HTMLImageElement` image का representation.
* `tf.Tensor`: एक वैकल्पिक `tf.Tensor` image का representation.
* `tf.Tensor4D`: एक वैकल्पिक 4D `tf.Tensor` image का representation.

#### **Methods**

**`bitmap()`**

एक promise लौटाता है जो एक `ImageBitmap` image के representation पर resolve होता है. यदि image पहले से bitmap है, तो यह cached bitmap लौटाता है.

**`tensor()`**

एक `tf.Tensor` image के representation को लौटाता है. यदि image पहले से tensor है, तो यह cached tensor लौटाता है.

**`tensor4D()`**

एक promise लौटाता है जो एक 4D `tf.Tensor` image के representation पर resolve होता है. यदि image पहले से 4D tensor है, तो यह cached 4D tensor लौटाता है.

**`array()`**

एक promise लौटाता है जो image के JavaScript array representation पर resolve होता है. यदि image पहले से tensor है, तो यह tensor को array में convert करता है.

**`dims()`**

image के dimensions वाली array लौटाता है. यदि image bitmap है, तो यह लौटाता है `[width, height]`. यदि image एक tensor है, तो यह tensor का shape लौटाता है. यदि image एक HTML image element है, तो यह लौटाता है `[width, height]`.

**`dispose()`**

memory मुक्त करने के लिए image के tensor representations को dispose करता है.

**`static fromArray(array: tf.TensorLike)`**

एक नया `CVImage` instance दिए गए tensor-like array से बनाता है.
