Tfjs: uncaught (in promise) TypeError: Cannot read property 'length' of undefined

Created on 11 Apr 2018  路  2Comments  路  Source: tensorflow/tfjs

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.

Most helpful comment

Hi @kallols

Note that model.predict() takes a Tensor (api ref), whereas I suspect arr=response gives you a regular js array? Can you try wrapping that in a Tensor using tf.tensor?

All 2 comments

Hi @kallols

Note that model.predict() takes a Tensor (api ref), whereas I suspect arr=response gives you a regular js array? Can you try wrapping that in a Tensor using tf.tensor?

Duplicate of #166

Was this page helpful?
0 / 5 - 0 ratings

Related issues

beele picture beele  路  3Comments

nsthorat picture nsthorat  路  3Comments

take-kuma picture take-kuma  路  3Comments

Arturbarth picture Arturbarth  路  3Comments

kylemcdonald picture kylemcdonald  路  3Comments