Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public static loadModel(callback?: () => any) {
cocoSsd
.load()
.then((model: ObjectDetection) => {
ObjectDetector.model = model;
store.dispatch(updateObjectDetectorStatus(true));
const activeLabelType: LabelType = LabelsSelector.getActiveLabelType();
activeLabelType === LabelType.RECTANGLE && AIObjectDetectionActions.detectRectsForActiveImage();
callback && callback();
})
.catch((error) => {
// TODO
throw new Error(error);
})
}
async componentDidMount() {
try {
const stream = await navigator.mediaDevices.getUserMedia({
video: {
facingMode: "user"
},
audio: false
});
const model = await cocoSsd.load();
await this.setState({
videoElement: this.refs.video,
canvasElement: this.refs.canvas,
stream,
model
});
this.state.videoElement.srcObject = this.state.stream;
this.predictFrame();
} catch (err) {
console.log(err);
}
}
async ngOnInit() {
this.model = await cocoSsd.load({base: 'lite_mobilenet_v2'});
await this.detectFrame();
await this.videoRef.nativeElement.play();
}
return new Promise((resolve, reject) => {
cocoSsd.load({
modelUrl: SSD_NET_URL
}).then(model => {
this.ssdNet = model
this.ready = true
resolve()
}).catch(err => {
reject(err)
})
})
}
async loadCocoSsdModal() {
const modal = await cocossd.load({
base: 'mobilenet_v2'
})
return modal;
}
window.onload = () => modelPromise = cocoSsd.load();
async loadModel() {
this.model = await cocoSsd.load(this.config);
this.modelReady = true;
return this;
}
select.onchange = async (event) => {
const model = await modelPromise;
model.dispose();
modelPromise = cocoSsd.load(
{base: event.srcElement.options[event.srcElement.selectedIndex].value});
};