|
| 1 | +import { RnExecutorchError } from '../errors/errorUtils'; |
1 | 2 | import { LabelEnum, Triple, ResourceSource } from './common'; |
2 | 3 |
|
3 | 4 | /** |
@@ -95,3 +96,47 @@ export interface ImageSegmentationProps<C extends ModelSources> { |
95 | 96 | model: C; |
96 | 97 | preventLoad?: boolean; |
97 | 98 | } |
| 99 | + |
| 100 | +/** |
| 101 | + * Return type for the `useImageSegmentation` hook. |
| 102 | + * Manages the state and operations for image segmentation models. |
| 103 | + * |
| 104 | + * @typeParam L - The {@link LabelEnum} representing the model's class labels. |
| 105 | + * |
| 106 | + * @category Types |
| 107 | + */ |
| 108 | +export interface ImageSegmentationType<L extends LabelEnum> { |
| 109 | + /** |
| 110 | + * Contains the error object if the model failed to load, download, or encountered a runtime error during segmentation. |
| 111 | + */ |
| 112 | + error: RnExecutorchError | null; |
| 113 | + |
| 114 | + /** |
| 115 | + * Indicates whether the segmentation model is loaded and ready to process images. |
| 116 | + */ |
| 117 | + isReady: boolean; |
| 118 | + |
| 119 | + /** |
| 120 | + * Indicates whether the model is currently processing an image. |
| 121 | + */ |
| 122 | + isGenerating: boolean; |
| 123 | + |
| 124 | + /** |
| 125 | + * Represents the download progress of the model binary as a value between 0 and 1. |
| 126 | + */ |
| 127 | + downloadProgress: number; |
| 128 | + |
| 129 | + /** |
| 130 | + * Executes the model's forward pass to perform semantic segmentation on the provided image. |
| 131 | + * @param imageSource - A string representing the image source (e.g., a file path, URI, or base64 string) to be processed. |
| 132 | + * @param classesOfInterest - An optional array of label keys indicating which per-class probability masks to include in the output. `ARGMAX` is always returned regardless. |
| 133 | + * @param resizeToInput - Whether to resize the output masks to the original input image dimensions. If `false`, returns the raw model output dimensions. Defaults to `true`. |
| 134 | + * @returns A Promise resolving to an object with an `'ARGMAX'` `Int32Array` of per-pixel class indices, and each requested class label mapped to a `Float32Array` of per-pixel probabilities. |
| 135 | + * @throws {RnExecutorchError} If the model is not loaded or is currently processing another image. |
| 136 | + */ |
| 137 | + forward: <K extends keyof L>( |
| 138 | + imageSource: string, |
| 139 | + classesOfInterest?: K[], |
| 140 | + resizeToInput?: boolean |
| 141 | + ) => Promise<Record<'ARGMAX', Int32Array> & Record<K, Float32Array>>; |
| 142 | +} |
0 commit comments