ml5js / ml5-library

Friendly machine learning for the web! 🤖
https://ml5js.org
Other
6.46k stars 899 forks source link

CharRNN constructor's promise immediately resolves, instead of waiting for models to load #950

Closed silentsilas closed 3 years ago

silentsilas commented 4 years ago

I was following along one of the stateful CharRNN examples, when I noticed that it would throw an error whenever I tried to generate text the moment I landed on the page, despite disabling my button until charRNN says it's ready.

private async setupRNN() {
    // Create the character level generator with a pre trained model
    this.charRNN = async ml5.charRNN('/models/woolf/');
    console.log('this immediately fires. Network tab shows that it's still downloading the woolf models');
}
private async setupRNN() {
    // Create the character level generator with a pre trained model
    ml5.charRNN('/models/woolf/', () => {
        console.log('correctly fires this after woolf models are downloaded');
    });
}

Running Firefox 75.0 on a MacOS 10.15.4, using ml5.js v0.5.0.

EonYang commented 4 years ago

Thanks for your feed back~

this.charRNN = async ml5.charRNN('/models/woolf/');

Should async be await?

Would you mind to share a test repo that we can test at our end?

bomanimc commented 3 years ago

@silentsilas Thanks for highlighting this issue! We'll need to see your code or a minimal example in order to address this issue, so I'm going to close this for now. Please feel free to reopen this issue if you'd like to continue the discussion!