transcranial / keras-js

Run Keras models in the browser, with GPU support using WebGL
https://transcranial.github.io/keras-js
MIT License
4.96k stars 501 forks source link

Error: predict() must take an object where the keys are the named inputs of the model: #137

Open hmhwe opened 5 years ago

hmhwe commented 5 years ago

I have been trying to run a keras model in browser using keras.js. But whenever i try to predict I got the following error

Error: predict() must take an object where the keys are the named inputs of the model: Here is js code


handlePredict()
{
const model = new KerasJS.Model({
filepaths: {
model: 'model.json',
weights: 'model_weights.buf',
metadata: 'model_metadata.json'
},
gpu : true,
filesystem : true

})

model.ready().then(() =>{
  const inputData = {
    'input_1': new Float32Array(samples)
  }
  alert('Converted text = ' + inputData['input_1'])
  return model.predict(inputData['input_1'])
})
.then(output =>
  {
  alert('Predicted value : ' + output['fc1000']);
  })
.catch(err =>
  {
  alert(err);
  })

}

I am using keras-js 0.3.0 and keras 2.2.4 . Any help would be appreciated.