Brain.js-无法从文件加载的经过训练的模型中运行预测

时间:2018-07-17 12:32:51

标签: javascript node.js meteor machine-learning brain.js

我能够训练一个模型并将其保存到文件中,但是当我再次从文件中加载训练后的模型并尝试运行预测时,我得到了低于错误的信息。顺便说一句,我正在使用metor.js。 这是我的工作

var net_LSTM = new brain.recurrent.LSTMTimeStep();
 function (convertedQuotes) {
                const result = [].concat(convertedQuotes.map(Object.values));

                net_LSTM.train(result, {
                    iterations: 100,    // the maximum times to iterate the training data --> number greater than 0
                    errorThresh: 0.1,   // the acceptable error percentage from training data --> number between 0 and 1
                    log: true,           // true to use console.log, when a function is supplied it is used --> Either true or a function
                    logPeriod: 100,        // iterations between logging out --> number greater than 0
                    learningRate: 0.3,    // scales with delta to effect training rate --> number between 0 and 1
                    momentum: 0.1,        // scales with next layer's change value --> number between 0 and 1
                    callback: null,       // a periodic call back that can be triggered while training --> null or function
                    callbackPeriod: 10,   // the number of iterations through the training data between callback calls --> number greater than 0
                    timeout: Infinity     // the max number of milliseconds to train for --> number greater than 0

                });


                console.log("Trained Neuron --> ", net_LSTM.toJSON());
                const filename = path.join('C:\\Chidu\\Projects\\MeteorReactBoilerplate', __dirname, "network.json");

                fs.writeFileSync(filename, JSON.stringify(net_LSTM.toJSON()), function (err) {
                    if (err)
                        console.log(err);

                    console.log("The file was saved!");
                });                  
            }

从文件中读取经过训练的模型并进行预测

 runNeuron() {
            const filename = path.join('C:\\Chidu\\Projects\\MeteorReactBoilerplate', __dirname, "network.json");
            const obj = JSON.parse(fs.readFileSync(filename, 'utf8'));


            net_LSTM.fromJSON(obj);

            console.log("net_LSTM __> ", net_LSTM);

            let output_LSTM = net_LSTM.run(
                [[10759, 10754.65, 10757.25],
                    [10759, 10755.25, 10755.6],
                    [10757.85, 10755, 10755.1]]
            );        
            console.log("LSTM out put ---->", output_LSTM);        
        }

以下是我得到的错误:

Exception while invoking method 'runNeuron' TypeError: Cannot read property 'runInput' of undefined
    at LSTMTimeStep.run (C:\Chidu\Projects\MeteorReactBoilerplate\node_modules\brain.js\dist\recurrent\rnn-time-step.js:175:49)
    at MethodInvocation.runNeuron (imports/api/convertedQuotes.js:171:36)
    at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1767:12)
    at DDP._CurrentMethodInvocation.withValue (packages/ddp-server/livedata_server.js:719:19)
    at Meteor.EnvironmentVariable.EVp.withValue (packages\meteor.js:1189:12)
    at DDPServer._CurrentWriteFence.withValue (packages/ddp-server/livedata_server.js:717:46)
    at Meteor.EnvironmentVariable.EVp.withValue (packages\meteor.js:1189:12)
    at Promise (packages/ddp-server/livedata_server.js:715:46)
    at new Promise (<anonymous>)
    at Session.method (packages/ddp-server/livedata_server.js:689:23)
   at packages/ddp-server/livedata_server.js:559:43

0 个答案:

没有答案