Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Saving Models #2

Closed
lmangani opened this issue Dec 1, 2018 · 4 comments
Closed

Saving Models #2

lmangani opened this issue Dec 1, 2018 · 4 comments
Labels
enhancement New feature or request

Comments

@lmangani
Copy link

lmangani commented Dec 1, 2018

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!

@yawetse
Copy link
Member

yawetse commented Dec 15, 2018

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!

@yawetse yawetse added the enhancement New feature or request label Dec 15, 2018
@yawetse
Copy link
Member

yawetse commented Feb 15, 2019

@lmangani the binding for tf save functions is on it's way! also you can import the built file using common js

@yawetse
Copy link
Member

yawetse commented Feb 15, 2019

@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));

@yawetse
Copy link
Member

yawetse commented May 10, 2019

@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);

@yawetse yawetse closed this as completed May 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants