Skip to main content
Version: 0.4.x

StyleTransferModule

TypeScript API implementation of the useStyleTransfer hook.

Reference​

import {
StyleTransferModule,
STYLE_TRANSFER_CANDY,
} from 'react-native-executorch';

const imageUri = 'path/to/image.png';

// Loading the model
await StyleTransferModule.load(STYLE_TRANSFER_CANDY);

// Running the model
const generatedImageUrl = await StyleTransferModule.forward(imageUri);

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<string>Executes the model's forward pass, where input can be a fetchable resource or a Base64-encoded string.
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​

To run the model, you can use the forward method. It accepts one argument, which is the image. The image can be a remote URL, a local file URI, or a base64-encoded image. The method returns a promise, which can resolve either to an error or a URL to generated image.