fromJSON not Working (I think I solved it)
See original GitHub issueDISCLAIMER: I think I solved it, explanation below. If I just swapped a problem by another, please inform me.
What is wrong?
When I am trying to load a trained NN from a file, I get an error saying that I cannot read property ‘bias’ of undefined.
Where does it happen?
In the fromJSON function
How do we replicate the issue?
I replicated it by just trying to load a trained model from memory.
How important is this (1-5)?
It prevented me from using trained models, which is a big deal, so I guess it’s, like, 4 or 5. I may be stupid tho, maybe I messed up saving and reading the JSON somehow.
Expected behavior (i.e. solution)
It should’ve loaded the model.
Here’s how I fixed it (there is probably a nicer way, but I didn’t want to get into how the library works and stuff) :
I figured by debugging that the loop for(var j in nodes)
goes for some reason to the 398th property of the object (the layer has only 397, and I figured that’s one too much). All I did then was swapping the for ... in ...
format to a standard loop: for (var t = 0; t < nodes.length; t++)
and then just assigning var j = t.toString()
since t was the number as a string.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
Are you going to open a PR for this issue? We’d love to gain you as a contributor!
const lstm = new brain.recurrent.LSTM(); lstm.fromJSON(myjson); const result = lstm.train(trainingData, { iterations: 15000, log: details => console.log(details), errorThresh: 0.011 });
const updatedjson = lstm.toJSON();
//, { flag: ‘a+’ } fs.writeFile(“results.json”, JSON.stringify(updatedjson), function (err) { if (err) throw err; console.log(‘The “data to write” was appended to file!’); });
result.json file needs to have train data for new training and old training
how can i do this?