-
Notifications
You must be signed in to change notification settings - Fork 903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Classifier with Feature Extractor" might not work with 3+ classes. #164
Comments
I'll look into this. But changing the hyperparameters might help: https://ml5js.org/docs/FeatureExtractor#parameters |
Thanks for the answer! |
For some reason numClasses is always = 2 whatever I put into hyperparameters object |
I experienced the same issue, a quick fix that's working for me is to set numClasses explicitely featureExtractor = ml5.featureExtractor('MobileNet', modelReady);
featureExtractor.numClasses=3 Then by putting a breakpoint in function classify() {
classifier.classify(gotResults);
} And inspecting classifier properties, numClasses is at 3. I changed a bit the code with a "Add bird image" button, using similar pattern than "Add dog" and "Add cat" and it works correctly, distinguishing 3 classes. I put the working example on p5.js : |
@gick great solutions! |
<3 thank you for this!!!! |
I investigated this a bit more and another way to do this is the following: featureExtractor = ml5.featureExtractor('MobileNet', { numClasses: 3 }, modelReady); The number of classes has to be set in advance b/c when examples are added they are "one-hot encoded" according to the total number of classes. This is distinctly different than the KNNClassifier examples which builds up the examples and labels on the fly. In light of this...
featureExtractor = ml5.featureExtractor('MobileNet', modelReady);
classifier = featureExtractor.classification(3, video, videoReady); or in the case of not working with video featureExtractor = ml5.featureExtractor('MobileNet', modelReady);
classifier = featureExtractor.classification(3); |
Yes, that's the default behavior (see docs) and I believe we fix this in a PR a few months ago. Perhaps adding an example with more classes will help |
Thanks @cvalenzuela. Thinking about this a bit more it feels like the number of classes should be set when calling classifier = featureExtractor.classification({ numClasses: 3 }); Also, probably worth discussing if we make the terminology more consistent with |
Thanks for this!! i've been stuck for a minute here trying to figure out why it never classifies the last class added. @shiffman Don't you think the function |
I imagine it to be something like this inside the
|
Thanks for this! Tested both methods, worked for me. featureExtractor = ml5.featureExtractor('MobileNet',{numClasses:4},function(){
console.log("model is loaded...");
}); and featureExtractor = ml5.featureExtractor('MobileNet',function(){
console.log("model is loaded...");
});
featureExtractor.numClasses = 4; |
Hi All! This is now resolved with ml5js/ml5-examples#142. Closing up this issue for now. Thanks for this nice discussion! 🙏 |
In last update they change name to numClasses to numLabels |
|
For people using 0.4.1 or above, numClasses has been changed to numLabels.
|
can u show ur all code i still dont get which line to add ur code to make my model can predict more that 2 class |
I create and train a featureExtractor with 10 classes and I save that onto a server. When I load this in a classifier. When I examine the JSON, I can see a key ml5Specs.mapStringToIndex which contains the 10 classes. However, I cannot get it to classify more than the first 2 classes. I have tried the fixes above with no luck. Heres my classifier code:
|
The given example works smoothly with 2 classes:
https://ml5js.org/docs/custom-classifier
...but adding a 3rd prediction class doesn't seem to be working yet.
Reproduction sketch:
https://alpha.editor.p5js.org/CedHon/sketches/S1yCjnr-7
Let me know if I can add any detail ;)
The text was updated successfully, but these errors were encountered: