Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ TypeScript API implementation of the [useVAD](../../03-hooks/01-natural-language
```typescript
import { VADModule, FSMN_VAD } from 'react-native-executorch';

const model = new VADModule();
await model.load(FSMN_VAD, (progress) => {
console.log(progress);
});
const model = await VADModule.fromModelName(
{ modelSource: FSMN_VAD },
(progress) => console.log(progress)
);

await model.forward(waveform);
```
Expand All @@ -28,14 +28,14 @@ All methods of `VADModule` are explained in details here: [`VADModule` API Refer

## Loading the model

To initialize the module, create an instance and call the [`load`](../../06-api-reference/classes/VADModule.md#load) method with the following parameters:
To create a ready-to-use instance, call the static [`fromModelName`](../../06-api-reference/classes/VADModule.md#frommodelname) factory with the following parameters:

- [`model`](../../06-api-reference/classes/VADModule.md#model) - Object containing:
- [`modelSource`](../../06-api-reference/classes/VADModule.md#modelsource) - Location of the used model.
- `model` - Object containing:
- `modelSource` - Location of the model binary.

- [`onDownloadProgressCallback`](../../06-api-reference/classes/VADModule.md#ondownloadprogresscallback) - Callback to track download progress.
- `onDownloadProgress` - Optional callback to track download progress (value between 0 and 1).

This method returns a promise, which can resolve to an error or void.
The factory returns a promise that resolves to a loaded `VADModule` instance.

For more information on loading resources, take a look at [loading models](../../01-fundamentals/02-loading-models.md) page.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ import {

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

// Creating an instance
const classificationModule = new ClassificationModule();

// Loading the model
await classificationModule.load(EFFICIENTNET_V2_S);
// Creating and loading the module
const classificationModule = await ClassificationModule.fromModelName({
modelSource: EFFICIENTNET_V2_S,
});

// Running the model
const classesWithProbabilities = await classificationModule.forward(imageUri);
Expand All @@ -35,14 +34,14 @@ All methods of `ClassificationModule` are explained in details here: [`Classific

## Loading the model

To initialize the module, create an instance and call the [`load`](../../06-api-reference/classes/ClassificationModule.md#load) method with the following parameters:
To create a ready-to-use instance, call the static [`fromModelName`](../../06-api-reference/classes/ClassificationModule.md#frommodelname) factory with the following parameters:

- [`model`](../../06-api-reference/classes/ClassificationModule.md#model) - Object containing:
- [`modelSource`](../../06-api-reference/classes/ClassificationModule.md#modelsource) - Location of the used model.
- `model` - Object containing:
- `modelSource` - Location of the model binary.

- [`onDownloadProgressCallback`](../../06-api-reference/classes/ClassificationModule.md#ondownloadprogresscallback) - Callback to track download progress.
- `onDownloadProgress` - Optional callback to track download progress (value between 0 and 1).

This method returns a promise, which can resolve to an error or void.
The factory returns a promise that resolves to a loaded `ClassificationModule` instance.

For more information on loading resources, take a look at [loading models](../../01-fundamentals/02-loading-models.md) page.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ import {
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);
// Creating and loading the module
const imageEmbeddingsModule = await ImageEmbeddingsModule.fromModelName({
modelSource: CLIP_VIT_BASE_PATCH32_IMAGE,
});

// Running the model
const embedding = await imageEmbeddingsModule.forward(
Expand All @@ -35,14 +34,14 @@ All methods of `ImageEmbeddingsModule` are explained in details here: [`ImageEmb

## Loading the model

To initialize the module, create an instance and call the [`load`](../../06-api-reference/classes/ImageEmbeddingsModule.md#load) method with the following parameters:
To create a ready-to-use instance, call the static [`fromModelName`](../../06-api-reference/classes/ImageEmbeddingsModule.md#frommodelname) factory with the following parameters:

- [`model`](../../06-api-reference/classes/ImageEmbeddingsModule.md#model) - Object containing:
- [`modelSource`](../../06-api-reference/classes/ImageEmbeddingsModule.md#modelsource) - Location of the used model.
- `model` - Object containing:
- `modelSource` - Location of the model binary.

- [`onDownloadProgressCallback`](../../06-api-reference/classes/ImageEmbeddingsModule.md#ondownloadprogresscallback) - Callback to track download progress.
- `onDownloadProgress` - Optional callback to track download progress (value between 0 and 1).

This method returns a promise, which can resolve to an error or void.
The factory returns a promise that resolves to a loaded `ImageEmbeddingsModule` instance.

For more information on loading resources, take a look at [loading models](../../01-fundamentals/02-loading-models.md) page.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ import {

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

// Creating an instance
const styleTransferModule = new StyleTransferModule();

// Loading the model
await styleTransferModule.load(STYLE_TRANSFER_CANDY);
// Creating and loading the module
const styleTransferModule = await StyleTransferModule.fromModelName({
modelSource: STYLE_TRANSFER_CANDY,
});

// Running the model
const generatedImageUrl = await styleTransferModule.forward(imageUri);
Expand All @@ -35,14 +34,14 @@ All methods of `StyleTransferModule` are explained in details here: [`StyleTrans

## Loading the model

To load the model, create a new instance of the module and use the [`load`](../../06-api-reference/classes/StyleTransferModule.md#load) method on it. It accepts an object:
To create a ready-to-use instance, call the static [`fromModelName`](../../06-api-reference/classes/StyleTransferModule.md#frommodelname) factory with the following parameters:

- [`model`](../../06-api-reference/classes/StyleTransferModule.md#model) - Object containing:
- [`modelSource`](../../06-api-reference/classes/StyleTransferModule.md#modelsource) - Location of the used model.
- `model` - Object containing:
- `modelSource` - Location of the model binary.

- [`onDownloadProgressCallback`](../../06-api-reference/classes/StyleTransferModule.md#ondownloadprogresscallback) - Callback to track download progress.
- `onDownloadProgress` - Optional callback to track download progress (value between 0 and 1).

This method returns a promise, which can resolve to an error or void.
The factory returns a promise that resolves to a loaded `StyleTransferModule` instance.

For more information on loading resources, take a look at [loading models](../../01-fundamentals/02-loading-models.md) page.

Expand Down
55 changes: 21 additions & 34 deletions docs/docs/06-api-reference/classes/ClassificationModule.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,13 @@
# Class: ClassificationModule

Defined in: [modules/computer_vision/ClassificationModule.ts:13](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/computer_vision/ClassificationModule.ts#L13)
Defined in: [modules/computer_vision/ClassificationModule.ts:14](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/computer_vision/ClassificationModule.ts#L14)

Module for image classification tasks.

## Extends

- `BaseModule`

## Constructors

### Constructor

> **new ClassificationModule**(): `ClassificationModule`

#### Returns

`ClassificationModule`

#### Inherited from

`BaseModule.constructor`

## Properties

### generateFromFrame()
Expand Down Expand Up @@ -116,7 +102,7 @@ Native module instance (JSI Host Object)

> **delete**(): `void`

Defined in: [modules/BaseModule.ts:100](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/BaseModule.ts#L100)
Defined in: [modules/BaseModule.ts:86](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/BaseModule.ts#L86)

Unloads the model from memory and releases native resources.

Expand All @@ -136,31 +122,31 @@ Always call this method when you're done with a model to prevent memory leaks.

> **forward**(`imageSource`): `Promise`\<\{\[`category`: `string`\]: `number`; \}\>

Defined in: [modules/computer_vision/ClassificationModule.ts:51](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/computer_vision/ClassificationModule.ts#L51)
Defined in: [modules/computer_vision/ClassificationModule.ts:57](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/computer_vision/ClassificationModule.ts#L57)

Executes the model's forward pass, where `imageSource` can be a fetchable resource or a Base64-encoded string.
Executes the model's forward pass to classify the provided image.

#### Parameters

##### imageSource

`string`

The image source to be classified.
A string image source (file path, URI, or Base64).

#### Returns

`Promise`\<\{\[`category`: `string`\]: `number`; \}\>

The classification result.
A Promise resolving to an object mapping category labels to confidence scores.

---

### forwardET()

> `protected` **forwardET**(`inputTensor`): `Promise`\<[`TensorPtr`](../interfaces/TensorPtr.md)[]\>

Defined in: [modules/BaseModule.ts:80](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/BaseModule.ts#L80)
Defined in: [modules/BaseModule.ts:66](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/BaseModule.ts#L66)

**`Internal`**

Expand Down Expand Up @@ -191,7 +177,7 @@ Array of output tensors.

> **getInputShape**(`methodName`, `index`): `Promise`\<`number`[]\>

Defined in: [modules/BaseModule.ts:91](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/BaseModule.ts#L91)
Defined in: [modules/BaseModule.ts:77](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/BaseModule.ts#L77)

Gets the input shape for a given method and index.

Expand Down Expand Up @@ -221,35 +207,36 @@ The input shape as an array of numbers.

---

### load()
### fromModelName()

> **load**(`model`, `onDownloadProgressCallback?`): `Promise`\<`void`\>
> `static` **fromModelName**(`model`, `onDownloadProgress?`): `Promise`\<`ClassificationModule`\>

Defined in: [modules/computer_vision/ClassificationModule.ts:21](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/computer_vision/ClassificationModule.ts#L21)
Defined in: [modules/computer_vision/ClassificationModule.ts:27](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/computer_vision/ClassificationModule.ts#L27)

Loads the model, where `modelSource` is a string that specifies the location of the model binary.
To track the download progress, supply a callback function `onDownloadProgressCallback`.
Creates a classification instance for a built-in model.

#### Parameters

##### model

Object containing `modelSource`.
An object specifying which built-in model to load and where to fetch it from.

###### modelName

`"efficientnet-v2-s"`

###### modelSource

[`ResourceSource`](../type-aliases/ResourceSource.md)

##### onDownloadProgressCallback?
##### onDownloadProgress?

(`progress`) => `void`

Optional callback to monitor download progress.
Optional callback to monitor download progress, receiving a value between 0 and 1.

#### Returns

`Promise`\<`void`\>

#### Overrides
`Promise`\<`ClassificationModule`\>

`BaseModule.load`
A Promise resolving to a `ClassificationModule` instance.
10 changes: 3 additions & 7 deletions docs/docs/06-api-reference/classes/ExecutorchModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Native module instance (JSI Host Object)

> **delete**(): `void`

Defined in: [modules/BaseModule.ts:100](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/BaseModule.ts#L100)
Defined in: [modules/BaseModule.ts:86](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/BaseModule.ts#L86)

Unloads the model from memory and releases native resources.

Expand Down Expand Up @@ -161,7 +161,7 @@ An array of output tensor pointers.

> `protected` **forwardET**(`inputTensor`): `Promise`\<[`TensorPtr`](../interfaces/TensorPtr.md)[]\>

Defined in: [modules/BaseModule.ts:80](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/BaseModule.ts#L80)
Defined in: [modules/BaseModule.ts:66](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/BaseModule.ts#L66)

**`Internal`**

Expand Down Expand Up @@ -192,7 +192,7 @@ Array of output tensors.

> **getInputShape**(`methodName`, `index`): `Promise`\<`number`[]\>

Defined in: [modules/BaseModule.ts:91](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/BaseModule.ts#L91)
Defined in: [modules/BaseModule.ts:77](https://github.com/software-mansion/react-native-executorch/blob/main/packages/react-native-executorch/src/modules/BaseModule.ts#L77)

Gets the input shape for a given method and index.

Expand Down Expand Up @@ -248,7 +248,3 @@ Optional callback to monitor download progress.
#### Returns

`Promise`\<`void`\>

#### Overrides

`BaseModule.load`
Loading
Loading