-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathImageSegmentationModule.ts
More file actions
34 lines (30 loc) · 1.02 KB
/
ImageSegmentationModule.ts
File metadata and controls
34 lines (30 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { BaseModule } from '../BaseModule';
import { _ImageSegmentationModule } from '../../native/RnExecutorchModules';
import { getError } from '../../Error';
import { DeeplabLabel } from '../../types/image_segmentation';
export class ImageSegmentationModule extends BaseModule {
static module = new _ImageSegmentationModule();
static async forward(
input: string,
classesOfInterest?: DeeplabLabel[],
resize?: boolean
) {
try {
const stringDict = await (this.module.forward(
input,
(classesOfInterest || []).map((label) => DeeplabLabel[label]),
resize || false
) as ReturnType<_ImageSegmentationModule['forward']>);
let enumDict: { [key in DeeplabLabel]?: number[] } = {};
for (const key in stringDict) {
if (key in DeeplabLabel) {
const enumKey = DeeplabLabel[key as keyof typeof DeeplabLabel];
enumDict[enumKey] = stringDict[key];
}
}
return enumDict;
} catch (e) {
throw new Error(getError(e));
}
}
}