ml5js / ml5-next-gen

Repo for next generation of ml5.js: friendly machine learning for the web! 🤖
https://ml5js.org/
Other
59 stars 20 forks source link

`topk` in the `options` for `imageClassifier` doesn't work #166

Open jackbdu opened 2 months ago

jackbdu commented 2 months ago

In ml5@1.0.1, when initializing the imageClassifier object, passing { topk: 5 } as options does not seem to affect the number of labels to return. On the other hand, specifying kNumber works fine when calling imageClassifier.classifyStart(media, ?kNumber, callback);

Tagging relevant issues/PRs for reference: #71 #83

shiffman commented 2 months ago

Thank you @jackbdu for pointing this out! Tagging @OrpheasK who worked on the original implementation to check the code.

I additionally wonder how universally understood or clear topk is? It is documented as "The number of top predictions to return, applicable to MobileNet."

Should we consider our own name here (like we use "confidence" instead of "score" across all models) or is topk sufficient? We could also consider a glossary entry.

OrpheasK commented 2 months ago

I looked into this and while there is a simple workaround to correct it and have the topk parameter actually apply to the number of classes, maybe it is a chance to address the first issue of #83 raised by @lindapaiste an mentioned here. The topk parameter can only currently apply to MobileNet and is overridden by kNumber.

Since it is correctly documented in the website, correcting the issue (and perhaps renaming the parameter @shiffman) is a simple solution, we might also consider however which parameter to make the universal one for choosing the number of classes.

shiffman commented 3 weeks ago

This has now been addressed in #179, I've tested this with the imageClassifier-webcam example, adding the argument to classifyStart() produces the desired result:

// Get the top 25 labels
classifier.classifyStart(video, 25, gotResult);

Should an example include this feature or is it just a matter of making sure the documentation is clear?