# inferencejs Reference

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

### Installation

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

`npm install inferencejs`

### Getting Started

शुरुआत करें `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();
const workerId = await inferEngine.startWorker("[PROJECT URL SLUG]", [VERSION NUMBER], PUBLISHABLE_KEY);

// model के खिलाफ inferences करें
const result = await inferEngine.infer(workerId, img);
```

## API

### InferenceEngine

**`new InferenceEngine()`**

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

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

दिए गए model के लिए एक नया worker शुरू करता है और लौटाता है `workerId`. **महत्वपूर्ण**- `publishableKey` आवश्यक है और आपके project settings folder में Roboflow से प्राप्त किया जा सकता है.

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

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

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

दिए गए worker को रोकता है `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`**

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

**`leftEye.y`**

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

**`rightEye.x`**

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

**`rightEye.y`**

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

**`yaw`**

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

**`pitch`**

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

### `CVImage`

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

#### **Constructor**

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

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

#### **Methods**

**`bitmap()`**

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

**`tensor()`**

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

**`tensor4D()`**

एक promise लौटाता है जो image के 4D `tf.Tensor` 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` दिए गए tensor-like array से instance बनाता है.
