繁体   English   中英

当我尝试使用tensorflow.js模型进行预测时,出现错误:Uncaught TypeError:无法读取未定义的属性“ length”

[英]When I try to make a prediction using a tensorflow.js model I get the error: Uncaught TypeError: Cannot read property 'length' of undefined

我正在尝试创建一个使用深度学习模型进行实时情感分析的网页。

当我使用model.predict()函数时,出现错误:Uncaught TypeError:无法读取未定义的属性“ length”。

我目前正在使用1.2.3 of tensorflow.js版本,但我曾尝试降级该版本,但无济于事。

这是我的代码:

<script src="https://cdnjs.cloudflare.com/ajax/libs/tensorflow/1.2.3/tf.js"></script>
<script type="text/javascript">
    async function init()   {
       model =  await tf.loadLayersModel('http://127.0.0.1:8000/model.json');
       model.predict([[tf.zeros(500)]]);
    };
    init();
</script>

我收到以下错误:

training.ts:320 Uncaught TypeError: Cannot read property 'length' of undefined
    at checkInputData (training.ts:320)
    at t.predict (training.ts:1101)
    at t.predict (models.ts:780)
    at <anonymous>:1:7

这个问题似乎来自这里[[tf.zeros(500)]] 如果模型具有多个输入条目,则model.predicts将张量或张量数组作为参数。

根据模型的InputShape, tf.zeros(500)应该足够,或者可能是tf.zeros(500).reshape(appropriateShape)

暂无
暂无

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

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