# inferencejs Reference

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

### Installation

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

`npm install inferencejs`

### शुरू करें

को शुरू करके आरंभ करें `InferenceEngine`. यह एक background worker शुरू करेगा जो user interface को block किए बिना models डाउनलोड और\
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` आवश्यक है और इसे Roboflow से आपके project settings folder में प्राप्त किया जा सकता है।

**`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`**

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

**`leftEye.y`**

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

**`rightEye.x`**

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

**`rightEye.y`**

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

**`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` 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` दिए गए tensor-like array से instance बनाता है।


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.roboflow.com/roboflow/roboflow-hi/deploy/sdks/web-browser/web-inference.js/inferencejs-reference.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
