ImageEmbeddingsModule
TypeScript API implementation of the useImageEmbeddings hook.
API Reference
- For detailed API Reference for
ImageEmbeddingsModulesee:ImageEmbeddingsModuleAPI Reference. - For all image embeddings models available out-of-the-box in React Native ExecuTorch see: Image Embeddings Models.
High Level Overview
import {
ImageEmbeddingsModule,
CLIP_VIT_BASE_PATCH32_IMAGE,
} from 'react-native-executorch';
// Creating an instance
const imageEmbeddingsModule = new ImageEmbeddingsModule();
// Loading the model
await imageEmbeddingsModule.load(CLIP_VIT_BASE_PATCH32_IMAGE);
// Running the model
const embedding = await imageEmbeddingsModule.forward(
'https://url-to-image.jpg'
);
Methods
All methods of ImageEmbeddingsModule are explained in details here: ImageEmbeddingsModule API Reference
Loading the model
To initialize the module, create an instance and call the load method with the following parameters:
-
model- Object containing:modelSource- Location of the used model.
-
onDownloadProgressCallback- Callback to track download progress.
This method returns a promise, which can resolve to an error or void.
For more information on loading resources, take a look at loading models page.
Running the model
forward 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.