我正在尝试创建一个使用深度学习模型来执行实时情感分析的网页。
当我使用model.predict()函数时,我得到这样的错误:未捕获长度:无法读取未定义的属性‘TypeError’。
我目前使用的是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发布于 2019-07-24 22:09:06
这个问题似乎来自这里,[[tf.zeros(500)]]。在模型有多个输入条目的情况下,model.predicts将张量或张量数组作为参数。
根据模型的InputShape,tf.zeros(500)应该足够了,也可以是tf.zeros(500).reshape(appropriateShape)
https://stackoverflow.com/questions/57182735
复制相似问题