Skip to main content
Version: Next

ImageEmbeddingsModule

TypeScript API implementation of the useImageEmbeddings hook.

Reference

import {
ImageEmbeddingsModule,
CLIP_VIT_BASE_PATCH_32_IMAGE_ENCODER,
} from 'react-native-executorch';

// Loading the model
await ImageEmbeddingsModule.load(CLIP_VIT_BASE_PATCH_32_IMAGE_ENCODER);

// Running the model
const embedding = await ImageEmbeddingsModule.forward(
'https://url-to-image.jpg'
);

Methods

MethodTypeDescription
load(modelSource: ResourceSource): Promise<void>Loads the model, where modelSource is a string that specifies the location of the model binary.
forward(input: string): Promise<number[]>Executes the model's forward pass, where input is a URI/URL to image that will be embedded.
onDownloadProgress(callback: (downloadProgress: number) => void): anySubscribe to the download progress event.

Type definitions

type ResourceSource = string | number | object;

Loading the model

To load the model, use the load method. It accepts the modelSource which is a string that specifies the location of the model binary. For more information, take a look at loading models page. This method returns a promise, which can resolve to an error or void.

Running the model

It accepts one argument, which is a URI/URL to an image you want to encode. The function returns a promise, which can resolve either to an error or an array of numbers representing the embedding.