brain.js icon indicating copy to clipboard operation
brain.js copied to clipboard

Train imported model from JSON fails

Open jemmali-git opened this issue 4 years ago • 7 comments

Trying to train an imported model from JSON fails.

Use case:

 let net = new LSTM();
      const trainingData = [
        {
          input: 'hi',
          output: 'mom',
        },
        {
          input: 'howdy',
          output: 'dad',
        },
        {
          input: 'hello',
          output: 'sis',
        },
        {
          input: 'yo',
          output: 'bro',
        },
      ];
      net.train(trainingData, { iterations: 20 });

      const net2 = new LSTM().fromJSON(net.toJSON());
      net2.train(trainingData, { iterations: 20 });
      net2.run('hi');

Error:

Error: Network error rate is unexpected NaN, check network configurations and try again.
 Most probably input format is not correct or training data is not enough. 

    at LSTM.train (brain.js\src\recurrent\rnn.ts:628:15)

Fix: Setting dataFormatter.isSetup to true in DataFormatter.fromJSON solve the problem

    dataFormatter.isSetup = true;

So is there any drawback for this Fix ?

jemmali-git avatar Nov 01 '21 13:11 jemmali-git

I am actually at this point too. Anything new?

thxrben avatar Nov 21 '21 22:11 thxrben

Same problem. I store the model in a json, try to load it, but it just fails with the same error.

GoldenretriverYT avatar Mar 08 '22 07:03 GoldenretriverYT

This has been resolved in https://www.npmjs.com/package/brain.js/v/2.0.0-beta.11. Here is a working example: https://observablehq.com/@robertleeplummerjr/brain-js-issue-741.

robertleeplummerjr avatar Apr 12 '22 15:04 robertleeplummerjr

This isn't solved. When trying to train the model after loading fromJSON, it still fails as they describe in the issue:

image

TejasQ avatar Jul 15 '22 23:07 TejasQ

It's the same issue as #787

TejasQ avatar Jul 15 '22 23:07 TejasQ

Thanks for reproducing. I'll look at this early this week.

robertleeplummerjr avatar Jul 16 '22 00:07 robertleeplummerjr

Thanks for reproducing. I'll look at this early this week.

Any progress on figuring this out? This is pretty much useless without being able to save a previous network.

cpgb85 avatar Aug 05 '22 04:08 cpgb85