When I try to make a prediction using a tensorflow.js model I get the error: Uncaught TypeError: Cannot read property 'length' of undefined
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()
函数时出现错误:
未捕获的类型错误:无法读取未定义的 属性 '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)
我正在尝试创建一个使用深度学习模型执行实时情绪分析的网页。
当我使用 model.predict()
函数时出现错误:
未捕获的类型错误:无法读取未定义的 属性 '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)