Roboflow Docs
DashboardResourcesProducts
  • Product Documentation
  • Developer Reference
  • Changelog
  • Roboflow Documentation
  • Quickstart
  • Workspaces
    • Workspaces, Projects, and Models
    • Create a Workspace
    • Manage Team Members
    • Role-Based Access Control
    • Usage Based Pricing
    • Delete a Workspace
  • Workflows
    • What is Workflows?
    • Create a Workflow
    • Build a Workflow
    • Test a Workflow
    • Deploy a Workflow
    • Workflow Examples
      • Multimodal Model Workflow
    • Share a Workflow
    • Workflows AI Assistant
  • Dataset Management
    • Create a Project
    • Upload Images, Videos, and Annotations
      • Import Data from Cloud Providers
        • AWS S3 Bucket
        • Azure Blob Storage
        • Google Cloud Storage
      • Import from Roboflow Universe
    • Manage Datasets
      • Dataset Batches
      • Search a Dataset
      • Set Dataset Classes
      • Add Tags to Images
      • Create an Annotation Attribute
      • Delete an Image
    • Dataset Versions
      • Create a Dataset Version
      • Preprocess Images
      • Augment Images
      • Delete a Version
      • Export a Dataset Version
    • Dataset Analytics
    • Merge Projects
    • Delete a Project
    • Project Folders
    • Make a Project Public
  • Annotate
    • Introduction to Roboflow Annotate
    • Annotate an Image
      • Keyboard Shortcuts
      • Comment on an Image
      • Annotation History
      • Similarity Search
    • AI Labeling
      • Label Assist
      • Enhanced Smart Polygon with SAM
        • Smart Polygon (Legacy)
      • Box Prompting
      • Auto Label
    • Set Keypoint Skeletons
    • Annotate Keypoints
    • Set Multimodal Prefixes
    • Collaborate on Annotations
    • Annotation Insights
  • Train
    • Train a Model
      • Train from a Universe Checkpoint
      • Train from Azure Vision
      • Train from Google Cloud
    • Roboflow Instant
    • Cancel a Training Job
    • Stop Training Early
    • View Training Results
    • View Trained Models
    • Evaluate Trained Models
  • Deploy
    • Deploy a Model or Workflow
    • Managed Deployments
    • Serverless Hosted API V2
      • Use in a Workflow
      • Use with the REST API
      • Run an Instant Model
    • Serverless Hosted API
      • Object Detection
      • Classification
      • Instance Segmentation
        • Semantic Segmentation
      • Keypoint Detection
      • Foundation Models
        • CLIP
        • OCR
        • YOLO-World
      • Video Inference
        • Use a Fine-Tuned Model
        • Use CLIP
        • Use Gaze Detection
        • API Reference
        • Video Inference JSON Output Format
      • Pre-Trained Model APIs
        • Blur People API
        • OCR API
        • Logistics API
        • Image Tagging API
        • People Detection API
        • Fish Detection API
        • Bird Detection API
        • PPE Detection API
        • Barcode Detection API
        • License Plate Detection API
        • Ceramic Defect Detection API
        • Metal Defect Detection API
    • Dedicated Deployments
      • Create a Dedicated Deployment
      • Make Requests to a Dedicated Deployment
      • Manage Dedicated Deployments with an API
    • Batch Processing
    • SDKs
      • Python inference-sdk
      • Web Browser
        • inferencejs Reference
        • inferencejs Requirements
      • Lens Studio
        • Changelog - Lens Studio
      • Luxonis OAK
    • Upload Custom Model Weights
    • Download Model Weights
    • Enterprise Deployment
      • License Server
      • Offline Mode
      • Kubernetes
      • Docker Compose
    • Monitor Deployed Models
      • Alerting
  • Universe
    • What is Roboflow Universe?
    • Find a Dataset on Universe
    • Explore Images in a Universe Dataset
    • Fork a Universe Dataset
    • Find a Model on Universe
    • Download a Universe Dataset
  • Support
    • Share a Workspace with Support
    • Delete Your Roboflow Account
Powered by GitBook
On this page
  • Installation
  • Getting Started
  • API
  • InferenceEngine
  • YOLOv8 YOLOv5
  • GazeDetections
  • CVImage

Was this helpful?

  1. Deploy
  2. SDKs
  3. Web Browser

inferencejs Reference

Reference for `inferencejs`, an edge library for deploying computer vision applications built with Roboflow to web/JavaScript environments

PreviousWeb BrowserNextinferencejs Requirements

Last updated 12 days ago

Was this helpful?

Learn more about inferencejs , our web SDK,

Installation

This library is designed to be used within the browser, using a bundler such as vite, webpack, parcel, etc. Assuming your bundler is set up, you can install by executing:

npm install inferencejs

Getting Started

Begin by initializing the InferenceEngine. This will start a background worker which is able to download and execute models without blocking the user interface.

import { InferenceEngine } from "inferencejs";

const PUBLISHABLE_KEY = "rf_a6cd..."; // replace with your own publishable key from Roboflow

const inferEngine = new InferenceEngine();
const workerId = await inferEngine.startWorker("[PROJECT URL SLUG]", [VERSION NUMBER], PUBLISHABLE_KEY);

//make inferences against the model
const result = await inferEngine.infer(workerId, img);

API

InferenceEngine

new InferenceEngine()

Creates a new InferenceEngine instance.

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

Starts a new worker for the given model and returns the workerId. Important- publishableKey is required and can be obtained from Roboflow in your project settings folder.

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

stopWorker(workerId: number): Promise<void>

Stops the worker with the given workerId.

YOLOv8 YOLOv5

The result of making an inference using the InferenceEngine on a YOLOv8 or YOLOv5 object detection model is an array of the following type:

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

GazeDetections

The result of making an inference using the InferenceEngine on a Gaze model. An array with the following type:

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

leftEye.x

The x position of the left eye as a floating point number between 0 and 1, measured in percentage of the input image width.

leftEye.y

The y position of the left eye as a floating point number between 0 and 1, measured in percentage of the input image height.

rightEye.x

The x position of the right eye as a floating point number between 0 and 1, measured in percentage of the input image width.

rightEye.y

The y position of the right eye as a floating point number between 0 and 1, measured in percentage of the input image height.

yaw

The yaw of the visual gaze, measured in radians.

pitch

The pitch of the visual gaze, measured in radians.

CVImage

A class representing an image that can be used for computer vision tasks. It provides various methods to manipulate and convert the image.

Constructor

The CVImage(image) class constructor initializes a new instance of the class. It accepts one image of one of the following types:

  • ImageBitmap: An optional ImageBitmap representation of the image.

  • HTMLImageElement: An optional HTMLImageElement representation of the image.

  • tf.Tensor: An optional tf.Tensor representation of the image.

  • tf.Tensor4D: An optional 4D tf.Tensor representation of the image.

Methods

bitmap()

Returns a promise that resolves to an ImageBitmap representation of the image. If the image is already a bitmap, it returns the cached bitmap.

tensor()

Returns a tf.Tensor representation of the image. If the image is already a tensor, it returns the cached tensor.

tensor4D()

Returns a promise that resolves to a 4D tf.Tensor representation of the image. If the image is already a 4D tensor, it returns the cached 4D tensor.

array()

Returns a promise that resolves to a JavaScript array representation of the image. If the image is already a tensor, it converts the tensor to an array.

dims()

Returns an array containing the dimensions of the image. If the image is a bitmap, it returns [width, height]. If the image is a tensor, it returns the shape of the tensor. If the image is an HTML image element, it returns [width, height].

dispose()

Disposes of the tensor representations of the image to free up memory.

static fromArray(array: tf.TensorLike)

Creates a new CVImage instance from a given tensor-like array.

Infer on n image using the worker with the given workerId. img can be created using new CVImage(HTMLImageElement | HTMLVideoElement | ImageBitmap | TFJS.Tensor) or

here
createImageBitmap