UNPKG

react-native-executorch

Version:

An easy way to run AI models in react native with ExecuTorch

28 lines (27 loc) 997 B
"use strict"; import { BaseModule } from '../BaseModule'; import { getError } from '../../Error'; import { DeeplabLabel } from '../../types/imageSegmentation'; import { ImageSegmentationNativeModule } from '../../native/RnExecutorchModules'; export class ImageSegmentationModule extends BaseModule { static nativeModule = ImageSegmentationNativeModule; static async load(modelSource) { return await super.load(modelSource); } static async forward(input, classesOfInterest, resize) { try { const stringDict = await this.nativeModule.forward(input, (classesOfInterest || []).map(label => DeeplabLabel[label]), resize || false); let enumDict = {}; for (const key in stringDict) { if (key in DeeplabLabel) { const enumKey = DeeplabLabel[key]; enumDict[enumKey] = stringDict[key]; } } return enumDict; } catch (e) { throw new Error(getError(e)); } } } //# sourceMappingURL=ImageSegmentationModule.js.map