ml5js / ml5-library

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

Can't train imageCalssifier #185

Closed Grizzly2212 closed 6 years ago

Grizzly2212 commented 6 years ago
   var features = ml5.featureExtractor("MobileNet", modelReady);
    var classifier;
    var img;
    function modelReady()
    {
      console.log("Model ready!");
      classifier = features.classification();
      img = new Image();
      img.src = "images/cat.jpg";
      classifier.addImage(img, 'cat', imageAdded);
    }

    function imageAdded()
    {
      console.log("Image added");
      classifier.train();
    }

Output:

index.html.html:16 Model ready! index.html.html:25 Image added webgl_util.js:164 Uncaught (in promise) Error: Requested texture size [0x0] is invalid. Mobilenet.js:153 Uncaught (in promise) Error: Add some examples before training!

Expected Output

index.html.html:16 Model ready! index.html.html:25 Image added

I can not understand what the problem is.

Image used: cat

cvalenzuela commented 6 years ago

By default, the featureExtractor expects two classes to be classified. You need to add more than 1 image to be able to train a custom classifier. See https://ml5js.org/docs/FeatureExtractor#parameters

Grizzly2212 commented 6 years ago

Yes, but what about that webgl_util.js:164 Uncaught (in promise) Error: Requested texture size [0x0] is invalid.

cvalenzuela commented 6 years ago

If you train a classifier with 1 image, the model will recognize everything as that one image. That doesn't make much sense. The error points to the fact that the model is searching for a second category of images to train, but it can't find one.