BrainJS / brain.js

🤖 GPU accelerated Neural networks in JavaScript for Browsers and Node.js
https://brain.js.org
MIT License
14.39k stars 1.07k forks source link

Train imported model from JSON fails #741

Open jemmali-git opened 3 years ago

jemmali-git commented 3 years ago

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 ?

Gandalf1783 commented 2 years ago

I am actually at this point too. Anything new?

GoldenretriverYT commented 2 years ago

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

robertleeplummerjr commented 2 years ago

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.

TejasQ commented 2 years ago

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

image

TejasQ commented 2 years ago

It's the same issue as #787

robertleeplummerjr commented 2 years ago

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

cpgb85 commented 2 years ago

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.