How can I train new information(Only the new information,not everything again, since it would cost too much performance) to my neural network made with brain.js after the first training?
Asked
Active
Viewed 2,290 times
4
-
1I assume you would save the net with `toJSON`, and then load with `fromJSON`, and then call `train` after loading. ps. Not used brain.js, but I assume this should do it. – Keith Jul 11 '18 at 23:59
-
Tried that, but doesn't seem to work. the neural network loses previous information with that. – peq42 Jul 12 '18 at 00:04
1 Answers
7
Its a little rough but you could achieve that using this structure:
if we join 2 training data sets, old with new one and then retrain with keepNetworkIntact: true
then our NN will be retrained much much faster than as if we retrain it from scratch.
let net = new brain.NeuralNetwork();
// pre-training
net.train([
{input: [0, 0], output: [0]},
{input: [1, 1], output: [0]}
]);
// resume training with new data set
net.train([
{input: [0, 0], output: [0]}, // old training data set
{input: [1, 1], output: [0]}
].concat([
{input: [0, 1], output: [1]}, // joining new training data set
{input: [1, 0], output: [1]},
],
{keepNetworkIntact:true}
);
i know Brain.JS was about to introduce a feature called resumeableTraining
which i am not sure if implemented. Its worth checking docs though.
Happy Braining!!!

Pruthvi Kumar
- 868
- 1
- 7
- 15
-
This solves the case, but I've notice something: If I use the browser version, installing gpu.js doesn't speed up the trainning. Why? – peq42 Jul 12 '18 at 00:38
-
Brain.js is dependent on gpu.js internally. Are you telling you are trying gpu.js without without node just on browser and brain.js training is not fast enough? – Pruthvi Kumar Jul 12 '18 at 00:55
-
If my solution helped, appreciate if you could accept that as an asnwer. Thanks – Pruthvi Kumar Jul 12 '18 at 00:56
-
Yes, both with and without gpu.js the performance is the same: takes around 3~5 seconds to train a small amount of information, with 250 iterations. – peq42 Jul 12 '18 at 01:03
-
Please note that Brain.JS already internally uses gpu.js. If you choose to stitch them together otherwise, you might need to explore BrainJS codebase to get a better hand of how it's internally wired so you can custom implement to your own specs. – Pruthvi Kumar Jul 12 '18 at 01:43
-
-
yes it does - https://towardsdatascience.com/gpu-accelerated-neural-networks-in-javascript-195d6f8e69ef – Pruthvi Kumar Jul 16 '18 at 00:32
-
[This way is deprecated](https://stackoverflow.com/questions/52798804/resuming-training-on-a-brain-js-neural-network-model), use fromJson instead – Fredrik Schön Mar 19 '19 at 21:42
-