This repository has been archived by the owner on Jul 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Saving Models #2
Labels
enhancement
New feature or request
Comments
Hi @lmangani I plan on adding a wrapper around save and load models. If you want to take a quick stab at it, pull requests are welcomed! |
@lmangani the binding for tf save functions is on it's way! also you can import the built file using common js |
@lmangani e.g. requiring tenosrscript without using import const TS = require('tensorscript/bundle/tensorscript.cjs');
const MultipleLinearRegression = TS.MultipleLinearRegression;
const Model = new MultipleLinearRegression({ epoch:100, });
const inputData = [
[ 0, 0, 0, 1, ],
[ 0, 1, 0, 0, ],
[ 0, 0, 0, 1, ]
];
const outputData = [
[ 1, ],
[ 0, ],
[ 1, ]
];
const predictionData = [
[ 0, 1, 0, 0 ],
[ 0, 0, 0, 1 ],
];
Model.train(inputData,outputData)
.then(() => Model.predict(predictionData,{probability: false}))
.then(predictions => {
console.log({ predictions }) //{ predictions: [ [ 0 ], [ 1 ] ] }
})
.catch(err=>console.error(err)); |
@lmangani saving and loading models are finally incorporated you can see the test (https://github.com/repetere/tensorscript/blob/master/test/unit/model_interface_spec.js) as an example or below loading a model const loadedModelPath = `file://path/to/some/model.json`;
const trainedModelToLoad = new MultipleLinearRegression({ });
await trainedModelToLoad.loadModel(loadedModelPath);
const loaded_predictions = await trainedModelToLoad.predict(input_x_matrix); saving a model const saveModelPath = `file://path/to/some/model_directory`;
const MLRModel = new MultipleLinearRegression({ fit: { epochs: 100, batchSize: 5, }, });
await MLRModel.train(x_matrix, y_matrix);
const savedModelStatus = await trainedMLR.saveModel(saveModelPath); |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Thanks for sharing your project! Having lots of fun with the examples (although I wish they worked without
import
in node) but having difficulties finding a clean way to save and reload generated models. Is there a native method and or a binding to use the tfjs save functions?Thanks in advance!
The text was updated successfully, but these errors were encountered: