ml5js / ml5-library

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

Can you suggest a working method for custum image classification (transfer learning, feature extraction)? #870

Closed corefox01 closed 3 years ago

corefox01 commented 5 years ago

I'm trying to make a custom image classifier on my own image dataset with transfer learning and featureExtractor, however its not working. I tried a lot of things as well based on @shiffman 's comment at ml5js/ml5-examples#142 I tried the following code with a lot of iterations:

const features = new ml5.FeatureExtractor('MobileNet');

const classifier = features.classification();
classifier.addImage(img1, 'cat');
classifier.addImage(img2, 'dog');
classifier.train();
classifier.classify(img3, gotResult);

const predictor = features.regression();
predictor.addImage(img1, 0.1);
predictor.addImage(img2, 0.9);
predictor.train();
predictor.predict(img2, gotResult);

However I'm getting the the error message of ml5js/ml5-examples#241 ml5js/ml5-examples#246 and #345 . the 'addImage' gives an error every time: tf-core.esm.js:17 Uncaught (in promise) Error: pixels passed to tf.browser.fromPixels() can not be null

Also in that case if I trying to use another method like 'knn.addExample(myImg, label)' Im getting the error: No input image.

I also tried the method in ml5js/ml5-library#861 but its really inaccurate.

If I'm using the 'createCapture(video)' as it shows in the video tutorial and in the examples, everyting is is working like a charm with the webcam, but if I'm trying to use still images from a folder its not.

Could you recommend a method which is working or at least give me a hint, what can be the problem? Thanks a lot!

pk-ux commented 4 years ago

Tried p5 image, a ImageData objects in both cases get

pixels passed to tf.browser.fromPixels() can not be null at t.fromPixels (:363:270008) at t.fromPixels (:363:48743) at fromPixels_ (:363:471786) at Object.fromPixels (:363:66218) at :9237:26 at :363:39143 at t.scopedRun (:363:39281) at t.tidy (:363:39045) at Object.Fe (:363:62063)

As per document p5 Image is supposed to work. "input - Optional. An HTML image or video element or a p5 image or video element. If not input is provided, the video element provided in the method-type will be used."

Call works fine if canvas object is passed.

Browny8161 commented 4 years ago

The only way to make this work is by adding the image to an HTML image element and then passing that image to the classifier. This is an error with the tensorflow backend and not of ml5.js Hope this helps

bomanimc commented 3 years ago

Thank you @Browny8161 for following up here! @corefox01, alternatively, something like Teachable Machine might be a useful tool for your goals.

Closing this issue for now, but please let me know if you have any questions!