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
Save and load? #2
Comments
This would be really useful to know. Thanks |
Also wondering about this. It would be nice not to have to retrain every time you want to use a model. |
The actual models that you train are JSON instances, so it really depends on how you use them. If you're transferring them to the front-end, you'll have to use local storage or something domain specific. Otherwise, you might consider standard node IO or a database. |
Its not the saving, but it the time takes to train the data. |
I think I may be misunderstanding the question, so bear with me a sec. There should be three principal tasks for this:
The only two things that you wouldn't have saved after completing these tasks is either the model (which you could save as a standard object) or the data that has yet to be run through the predictor. |
Thanks. I think I may be misunderstanding the question, so bear with me a sec. There should be three principal tasks for this:
The only two things that you wouldn't have saved after completing these — |
Gotcha. Suppose you create a new learner and train it: You might save it by:
|
Sweet. Dor
|
What about restoring a saved net? |
What do you mean by saved net?
|
You've explained how to export to a string so that it can be saved, but not how to load that string back so that we can work with it again in the future. |
I believe you should just use
|
JSON.stringify() returns a JSON object, containing only the data without circular references or methods. When doing |
This feature is totally unsupported at this time. Passing in a new object into mlp.MLP(JSON.parse(str)) will take you down a rabbit hole of "undefined" errors. |
Looking at mlp.js:
b_array and w_array are unspecified anywhere in this entire project. Passing in an object with data to mlp.MLP will necessarily fail because b_array and w_array are dead code with no reference anywhere in the project. |
looks like you can set any property on these instances, so you could save to json and then reload the data, setting the properties. definitely not ideal though as you need to know which properties to set. could also object.assign |
This is how I serialized and deserialized a MLP. I will cover only browser code as that is my interest, and only MLP as that is my interest, code should be easy adaptable to other types this library provides. The concept is that you will use each type constructor to ensure we end with the correct object interface, and then iterate over all properties serialized as JSON and restore them. In the case of the MLP, you will use two constructors, the MLP constructor and the HiddenLayer constructor, HiddenLayer is used internally by MLP when you call predict(); Create a index.html to train your MLP, refer to the MLP example to see how to train one. Then serialize using JSON.stringify to a <textarea> element. Copy the content of the <textarea> element and save to a js file, I named the variable LearnedData, add It should look like this:
Then to deserialize:
Hint: while you are advised by readme.md file to use http://joonku.com/js/machine_learning.min.js for browsers, when trying to guess how to deserialize it is better to download http://joonku.com/js/machine_learning.js so you can insert breakpoints and see what is happening and what constructors you need to correctly recreate your objects. |
Hi,
How do you save and then re-open a trained network?
It doesn't seem to be explained anywhere in the doc.
Thanks.
The text was updated successfully, but these errors were encountered: