javascript - Keras-js input data error in Node-Red (not recognized as Float32Array) -
after exporting keras model , weights, tried following code in node.js (v6.9.4), , runs ok:
const kerasjs = require('keras-js'); const model_folder = '... model_files_folder'; const model_file_path = { model: model_folder + 'model.json', weights: model_folder + 'model_weights.buf', metadata: model_folder + 'model_metadata.json' }; const model_config = { filepaths: model_file_path, gpu: false, filesystem: true }; const model = new kerasjs.model(model_config); model.ready().then(() => { const inputdata = { 'input': new float32array(5) } console.log('input: ' + inputdata.input); return model.predict(inputdata) }).then(outputdata => { var out = outputdata['output'] console.log('output: ' + out); }).catch(err => { console.error(err) })
i got result as:
> input: 0,0,0,0,0 output: 0.4446795582771301,0.0000053633639254258014,1.1930331722531662e-11,3.77190296774188e-8,1.060054266588395e-10
i changed settings.js file of node-red include keras-js:
functionglobalcontext: { os:require('os'), kerasjs:require('keras-js') // ... },
and test function wrote in node-red (v0.17.5):
const kerasjs = global.get('kerasjs'); (...model_folder, model_config, etc. same above codes tested in node.js...) model.ready() .then(() => { const inputdata = { 'input': new float32array(5) } node.warn('input: ' + inputdata.input); return model.predict(inputdata) }) .then(outputdata => { var out = outputdata['output'] node.warn('output: ' + out); msg.payload = { 'output': out }; node.send(msg); }) .catch(err => { node.error(err); }) return null;
but got following error:
function : (error) "error: predict() must take object values flattened data float32array."
i got confused since assigned inputdata.input float32array already. me fix this? thank you!
Comments
Post a Comment