Uncaught TypeError: model.predict is not a function

779 Views Asked by At

My code

const model = tf.loadLayersModel('../model/model.json');
// python
    function pyFun(arrayOne){
        var arrayReturn = new Array(5000);
        for (i=0;i<5000;i++){
            arrayReturn[i]=0;
        }
        var arrayTwo = arrayOne.map(myFunction);
        function myFunction(value,index,array){
            var absValue = 100*Math.abs(value);
            var roundValue = Math.round(absValue);
            return roundValue;
        }
        for(j=0;j<arrayTwo.length;j++){
            var TemValue = arrayTwo[j]
            arrayReturn[TemValue-1]=1;
        }
        // arrayReturn
        return arrayReturn;
    }
 x=pyFun([2.20,2.20,7.00,5.00,4.00,5.00,4.11,4.00,2.00,2.00,4.00,5.60]);
 const prediction = model.predict(x);

But the Chrome returns like this:

function.js:32 Uncaught TypeError: model.predict is not a function
    at function.js:32

I think 'model.predict()' is a normal function in deeplearning, why does the error occur?

1

There are 1 best solutions below

2
On

loadLayersModel is an async function. You need to wait for the Promise to resolve.

const model = await tf.loadLayersModel('../model/model.json');

The function call has to be awaited. Also, make sure this code is inside an async function.