BrainJS / brain.js

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

trainAsync is not a function #895

Open fangiridev opened 1 year ago

fangiridev commented 1 year ago

I get this error when trying to use 'net.trainAsync'

  <rejected> TypeError: net.trainAsync is not a function
      at train (/home/container/index.js:21:13)

Code:


  const pool = workerpool.pool();

  await net.trainAsync(data, {
    iterations: 2000,
    errorThresh: 0.01,
    log: true,
    logPeriod: 100,
    useWorkers: true,
    learningRate: 0.01,
    callbackPeriod: 10,
    callback: function(stats) {

      if (stats.accuracy > 0.9) {
        pool.terminate();
        console.log('Training finished');
        client.user.setPresence({ 
          status: 'online', 
          activities: [{ name: 'Estou pronta para uso!', type: 'WATCHING' }]
        });
      }
    }
  });
Vectorrent commented 1 year ago

Async training is only supported by a couple of classes. Most do not (and will never) support async training: https://github.com/BrainJS/brain.js#async-training

Since you didn't tell us what kind of network you're training, I can only assume you're using one of the unsupported classes.

To make the unsupported classes async, you have to use a worker, and the regular .train() method.