简体   繁体   English

未捕获的类型错误:model.predict 不是函数

[英]Uncaught TypeError: model.predict is not a function

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:但是 Chrome 会像这样返回:

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?我认为 'model.predict()' 是深度学习中的正常函数,为什么会出现错误?

loadLayersModel is an async function. loadLayersModel是一个异步函数。 You need to wait for the Promise to resolve.您需要等待 Promise 解决。

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.此外,请确保此代码位于异步函数内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM