How to load and save knn-classifier


I am beginner in Tensorflow.

I have already try tensorflow.js, mobilnet.js et knn-classifier in webbrowser for object classification.

I understand that, after training, I have to save the model.
But how to save and load “classifier” ?

// Sample of classification off pictures (img)

var _classifier = knnClassifier.create();
var _net = await mobilenet.load();

// add sample with manual classification of picture with 'classId':
const activation = _net.infer( img, true);
_classifier.addExample( activation, classId);

// ... then process add sample several times....

// Save informations on disk

// HOW to save classifier ?

// Retry with previous performances...
// renew model (or HOW to create new model without experience ?)
_net = await mobilenet.load();
await _net.model.load('downloads://my-model');

// how to LOAD classifier ? or HOW to UPDATE it from model ?

Best regards

Hi @fpi, If you have a knn-classifier in web browser you can save and load it by


await tf.loadLayersModel('http://model-server.domain/download/model.json');

For more details please refer to this documentation. Thank You.

Thank you.
But now I am working locally with nodejs.
So, I use this to save model:
const saveResults = await${this.settings.modelName});
This create a local sub-folder named “my-model-modelName”, and stores in it two files : model.json and weights.bin
To load my model, I use :
this.model = await tf.loadLayersModel(file://./my-model-${this.settings.modelName}/model.json, file://./my-model-${this.settings.modelName}/weights.json);

Best regards.