Reputation: 49
I use node.js/synaptic and want to save/import a trained network. I found here that I can save my network via
var standalone = myNetwork.standalone();
or
var standalone = myNetwork.toJSON();
I export it using the following code
fs.writeFile("./exported.js", standalone, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
And the exported file looke like this:
function (input) {
F = {
0: 0,
1: 1,
7: 0.0014116593126537414,
2: 3.596792839201632,
3: -6.56157679237169,
4: 0.9270641863334851,
5: 2.6804007136091412,
6: -7.488640978705175,
8: 0.0014096665306387395,
14: 0.9735501068596871,
9: -6.581289638080665,
10: 3.6056971760921814,
11: 0.90400906009467,
12: -7.485852355023438,
13: 2.7016881159975115,
15: 0.025750296293178904,
21: 0.05645764940459668,
16: -2.7936895640563675,
17: -2.8161504614692587,
18: -8.094384439882408,
19: 5.277628422194746,
20: 5.278233978413149,
22: 0.053270183228304326
};
F[0] = input[0];
F[1] = input[1];
F[2] = F[3];F[3] = F[4];F[3] += F[0] * F[5];F[3] += F[1] * F[6];F[7] = (1 / (1 + Math.exp(-F[3])));F[8] = F[7] * (1 - F[7]);
F[9] = F[10];F[10] = F[11];F[10] += F[0] * F[12];F[10] += F[1] * F[13];F[14] = (1 / (1 + Math.exp(-F[10])));F[15] = F[14] * (1 - F[14]);
F[16] = F[17];F[17] = F[18];F[17] += F[0] * F[19];F[17] += F[1] * F[20];F[21] = (1 / (1 + Math.exp(-F[17])));F[22] = F[21] * (1 - F[21]);
var output = [];
output[0] = F[7];
output[1] = F[14];
output[2] = F[21];
return output;
}
To import it I found I should use the require method. But running the simple file
var imp=require('./exported.js')
gives the error
Unexpected token (
Upvotes: 0
Views: 424
Reputation: 6313
Ok your exported.js
has to actually export something for you to require it.
Change your exported.js
file to something like this:
module.exports = exports = function ( input ) {
F = { something: input };
// this is where all your content of your original exported.js goes
return F;
}
Then in your code when you require the file you can run the function.
const imp = require('./exported.js');
console.log( imp('test') );
Hope this helps
Upvotes: 0