Skip to content
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

knnClassifier result after .save() and .load() - classIndex becomes undefined and label becomes number, labelToClassId disappears #1463

Open
ale24 opened this issue Apr 14, 2023 · 1 comment

Comments

@ale24
Copy link

ale24 commented Apr 14, 2023

Dear ml5 community,

I'm submitting a new issue. Please see the details below.

β†’ Step 1: Describe the issue πŸ“

KNNClassifier result after .save() and .load() in .classify() :
classIndex becomes undefined and label becomes number

somehow before .save() and .load() on .addExample() stage - I getting result I want with .classify() in label key as expected

but after .save() and .load() to reveal same prediction I need to set k: Optional. Number. to 1 and by hands look all keys in confidencesByLabel to find predicted label, or used Object.keys(result.confidencesByLabel)[result.label] without setting k: Optional. Number. also give satisfaction

I checked knnClassifier and it looks like after .save() labelToClassId inside it disappears - I think this is root of my problem! exampleShape also disappears, maybe other data also have differences, extra check needed...

β†’ Step 2: Screenshots or Relevant Documentation πŸ–Ό

results before .save() - https://i.imgur.com/UrKYtE1.png
results after .save() and .load() - https://i.imgur.com/sx3JJpg.png
knnClassifier before/after .save() and .load() - https://i.imgur.com/fhANlyb.png

β†’ Describe your setup πŸ¦„

used ml5.js version - https://unpkg.com/ml5@latest/dist/ml5.min.js
saved model - https://assets.editor.p5js.org/6425ed4ef6508e001a82ec9f/779262d9-d5be-4d32-ae82-8c835a3d1fe4.json

@ale24
Copy link
Author

ale24 commented Apr 14, 2023

another solution, maybe not valid in all situations, but it works in my

knnClassifier.load("model.json", function() {
    for (i in knnClassifier.getCount()) {
        knnClassifier.knnClassifier.labelToClassId[i] = parseInt(i);
    }
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants