ml5js / ml5-library

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

Loading a pretrained tensorflow.js model into ml5js error #884

Open mikkelmedm opened 5 years ago

mikkelmedm commented 5 years ago

I dont know if this is at all possible, but I have trained my own mobile-net model on two classes in keras. I then converted this model into tensorflow.js and made sure the weigths file was in .bin format to load them into ml5js. It still doesnt seem to work. I even added the "ml5-specs" in the json-file of my model. Now im stuck with this error:

"Uncaught (in promise) TypeError: Cannot read property 'load' of null at e. (index.js:51) at x (runtime.js:62) at Generator._invoke (runtime.js:296) at Generator.e.(anonymous function) [as next] (https://unpkg.com/ml5@0.1.2/dist/ml5.min.js:106:330884) at a (asyncToGenerator.js:17) at asyncToGenerator.js:15 at new Promise () at new t (_export.js:36) at e. (asyncToGenerator.js:14) at e. (index.js:52)"

Can only ml5js models be loaded into ml5?

shiffman commented 5 years ago

We would like this to be possible for sure! Did you try with 0.1.3. It's more likely that you'll need to load your model with the ml5.ImageClassifier() directly (I don't recall if the API will accept a full path but we should add that if not). The FeatureExtractor classifier always passes the image through the original MobileNet model first.

mikkelmedm commented 5 years ago

I get the same error with 0.1.3. When loading the model, i did: classifier = ml5.imageClassifier("./mobile/model.json", video, modelReady);

However, when first loading MobileNet, and then using a load button to load a model from files, it accepts the model. But now it says: "Error: Mobilenet Feature Extraction has not been set to be a regressor." Is that because I just have two classes? When setting it to regression, then the classify-function returns a null error. TypeError: Cannot read property 'predict' of null at Mobilenet.js:293 at tf-core.esm.js:17 at e.scopedRun (tf-core.esm.js:17) at e.tidy (tf-core.esm.js:17) at Object.t.tidy (tf-core.esm.js:17) at e. (Mobilenet.js:289) at x (runtime.js:62) at Generator._invoke (runtime.js:296) at Generator.e.(anonymous function) [as next] (https://unpkg.com/ml5@0.1.2/dist/ml5.min.js:106:330884) at a (asyncToGenerator.js:17)

mikkelmedm commented 5 years ago

Similar when using 0.1.3