Skip to content

Commit

Permalink
Make ImageNet's predict promise correct
Browse files Browse the repository at this point in the history
  • Loading branch information
meiamsome committed Feb 17, 2018
1 parent 123ae1c commit a4fdbd6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/ImageNet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MobileNet } from './../utils/mobileNet';
class ImageNet {
constructor(model) {
this.model = model;
this.ready = false;
this.readyPromise = null;
this.math = ENV.math;
if (this.model === 'SqueezeNet') {
this.net = new SqueezeNet(this.math);
Expand All @@ -22,14 +22,11 @@ class ImageNet {
}

async predict(img, num, callback) {
if (this.ready) {
this.getClasses(img, num, callback);
} else {
ImageNet.loadModel(this.net).then(() => {
this.ready = true;
this.getClasses(img, num, callback);
});
if (!this.readyPromise) {
this.readyPromise = ImageNet.loadModel(this.net);
}
await this.readyPromise;
return this.getClasses(img, num, callback);
}

// Private Method
Expand All @@ -45,7 +42,10 @@ class ImageNet {
});
});
results.sort((a, b) => b.probability - a.probability);
callback(results);
if (callback) {
callback(results);
}
return results;
}

static async loadModel(model) {
Expand Down

0 comments on commit a4fdbd6

Please sign in to comment.