react-native-executorch
Version:
An easy way to run AI models in React Native with ExecuTorch
19 lines (18 loc) • 831 B
JavaScript
;
import { ResourceFetcher } from '../../utils/ResourceFetcher';
import { ETError, getError } from '../../Error';
import { BaseModule } from '../BaseModule';
export class ObjectDetectionModule extends BaseModule {
async load(model, onDownloadProgressCallback = () => {}) {
const paths = await ResourceFetcher.fetch(onDownloadProgressCallback, model.modelSource);
if (paths === null || paths.length < 1) {
throw new Error('Download interrupted.');
}
this.nativeModule = global.loadObjectDetection(paths[0] || '');
}
async forward(imageSource, detectionThreshold = 0.7) {
if (this.nativeModule == null) throw new Error(getError(ETError.ModuleNotLoaded));
return await this.nativeModule.generate(imageSource, detectionThreshold);
}
}
//# sourceMappingURL=ObjectDetectionModule.js.map