I have imported a pre-trained keras model through a json file but while running the program I got the following error:
Uncaught (in promise) TypeError: Cannot read property 'length' of undefined
at h (tfjs@latest:1)
at t.predict (tfjs@latest:1)
at t.predict (tfjs@latest:1)
at Object.success (sample.js:19)
h @ tfjs@latest:1
t.predict @ tfjs@latest:1
t.predict @ tfjs@latest:1
(anonymous) @ sample.js:19
async function (async)
(anonymous) @ sample.js:14
u @ jquery.min.js:2
fireWith @ jquery.min.js:2
k @ jquery.min.js:2
(anonymous) @ jquery.min.js:2
This is my java script code below;
var a = (form.input1.value);
$.post('http://127.0.0.1:5000/',{"text":a}, async function(response)
{
//console.log('response: ',response);
var arr=response;
const model= await tf.loadModel('./json/model.json');
console.log(model.predict(arr))
});
Please let me know how to solve this issue.
Duplicate of #166
Most helpful comment
Hi @kallols
Note that model.predict() takes a
Tensor(api ref), whereas I suspectarr=responsegives you a regular js array? Can you try wrapping that in a Tensor using tf.tensor?