Skip to content

Commit 01b7083

Browse files
fix: style transfer crashes app, rename output -> outputType
1 parent f8251f2 commit 01b7083

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

docs/docs/03-hooks/02-computer-vision/useStyleTransfer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ You need more details? Check the following resources:
5757
To run the model, use the [`forward`](../../06-api-reference/interfaces/StyleTransferType.md#forward) method. It accepts two arguments:
5858

5959
- `input` (required) — The image to stylize. Can be a remote URL, a local file URI, a base64-encoded image (whole URI or only raw base64), or a [`PixelData`](../../06-api-reference/interfaces/PixelData.md) object (raw RGB pixel buffer).
60-
- `output` (optional) — Controls the return format:
60+
- `outputType` (optional) — Controls the return format:
6161
- `'pixelData'` (default) — Returns a `PixelData` object with raw RGB pixels. No file is written.
6262
- `'url'` — Saves the result to a temp file and returns its URI as a `string`.
6363

6464
:::info
65-
When `output` is `'url'`, the generated image is stored in your application's temporary directory.
65+
When `outputType` is `'url'`, the generated image is stored in your application's temporary directory.
6666
:::
6767

6868
## Example

docs/docs/04-typescript-api/02-computer-vision/StyleTransferModule.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ For more information on loading resources, take a look at [loading models](../..
5050
To run the model, use the [`forward`](../../06-api-reference/classes/StyleTransferModule.md#forward) method. It accepts two arguments:
5151

5252
- `input` (required) — The image to stylize. Can be a remote URL, a local file URI, a base64-encoded image (whole URI or only raw base64), or a [`PixelData`](../../06-api-reference/interfaces/PixelData.md) object (raw RGB pixel buffer).
53-
- `output` (optional) — Controls the return format:
53+
- `outputType` (optional) — Controls the return format:
5454
- `'pixelData'` (default) — Returns a `PixelData` object with raw RGB pixels. No file is written.
5555
- `'url'` — Saves the result to a temp file and returns its URI as a `string`.
5656

packages/react-native-executorch/src/hooks/computer_vision/useStyleTransfer.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,32 @@ export const useStyleTransfer = ({
1717
model,
1818
preventLoad = false,
1919
}: StyleTransferProps): StyleTransferType => {
20-
const { error, isReady, isGenerating, downloadProgress, runForward } =
21-
useModuleFactory({
22-
factory: (config, onProgress) =>
23-
StyleTransferModule.fromModelName(config, onProgress),
24-
config: model,
25-
deps: [model.modelName, model.modelSource],
26-
preventLoad,
27-
});
20+
const {
21+
error,
22+
isReady,
23+
isGenerating,
24+
downloadProgress,
25+
runForward,
26+
runOnFrame,
27+
} = useModuleFactory({
28+
factory: (config, onProgress) =>
29+
StyleTransferModule.fromModelName(config, onProgress),
30+
config: model,
31+
deps: [model.modelName, model.modelSource],
32+
preventLoad,
33+
});
2834

29-
const forward = (imageSource: string | PixelData) =>
30-
runForward((inst) => inst.forward(imageSource));
35+
const forward = <O extends 'pixelData' | 'url' = 'pixelData'>(
36+
imageSource: string | PixelData,
37+
outputType?: O
38+
) => runForward((inst) => inst.forward(imageSource, outputType));
3139

3240
return {
3341
error,
3442
isReady,
3543
isGenerating,
3644
downloadProgress,
3745
forward,
46+
runOnFrame,
3847
} as StyleTransferType;
3948
};

packages/react-native-executorch/src/modules/computer_vision/StyleTransferModule.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ export class StyleTransferModule extends VisionModule<PixelData | string> {
7171

7272
async forward<O extends 'pixelData' | 'url' = 'pixelData'>(
7373
input: string | PixelData,
74-
output?: O
74+
outputType?: O
7575
): Promise<O extends 'url' ? string : PixelData> {
76-
return super.forward(input, output === 'url') as Promise<
76+
return super.forward(input, outputType === 'url') as Promise<
7777
O extends 'url' ? string : PixelData
7878
>;
7979
}

packages/react-native-executorch/src/types/styleTransfer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ export interface StyleTransferType {
6767
* **Note**: For VisionCamera frame processing, use `runOnFrame` instead.
6868
*
6969
* @param input - Image source (string or PixelData object)
70-
* @param output - Output format: `'pixelData'` (default) returns raw RGBA pixel data; `'url'` saves the result to a temp file and returns its `file://` path.
71-
* @returns A Promise resolving to `PixelData` when `output` is `'pixelData'` (default), or a `file://` URL string when `output` is `'url'`.
70+
* @param outputType - Output format: `'pixelData'` (default) returns raw RGBA pixel data; `'url'` saves the result to a temp file and returns its `file://` path.
71+
* @returns A Promise resolving to `PixelData` when `outputType` is `'pixelData'` (default), or a `file://` URL string when `outputType` is `'url'`.
7272
* @throws {RnExecutorchError} If the model is not loaded or is currently processing another image.
7373
*/
7474
forward<O extends 'pixelData' | 'url' = 'pixelData'>(
7575
input: string | PixelData,
76-
output?: O
76+
outputType?: O
7777
): Promise<O extends 'url' ? string : PixelData>;
7878

7979
/**

0 commit comments

Comments
 (0)