[英]how to pass several tensor to a model.predict in tensorflow.js
我正在尝试使用 tensorflow.js 来运行我在 python 中创建的模型。 该模型有两个输入张量,一个是 [1, 60] 形状,另一个是 [1, 60, 1]。 我这样做:
var array1 = new Array(60).fill(0);
var tensor1 = tf.tensor(arr1, [1, 60);
var array2 = new Array(60).fill(1);
var tensor2 = tf.tensor(arr2, [1, 60, 1]);
var tensorResult = model.predict([tensor1, tensor2]);
但它给了我这个信息:
错误:检查模型时出错:您传递给模型的张量数组不是模型预期的大小。 预计会看到 2 个张量,但得到了 1 个张量。
模型摘要():
__________________________________________________________________________________________________
Layer (type) Output shape Param # Receives inputs
==================================================================================================
l_word (InputLayer) [null,60] 0
__________________________________________________________________________________________________
l_embWord (Embedding) [null,60,300] 164395500 l_word[0][0]
__________________________________________________________________________________________________
l_company (InputLayer) [null,60,1] 0
__________________________________________________________________________________________________
l_concat (Concatenate) [null,60,301] 0 l_embWord[0][0]
l_company[0][0]
__________________________________________________________________________________________________
l_bLstm (Bidirectional) [null,128] 187392 l_concat[0][0]
__________________________________________________________________________________________________
l_dense (Dense) [null,16] 2064 l_bLstm[0][0]
__________________________________________________________________________________________________
l_dropout (Dropout) [null,16] 0 l_dense[0][0]
__________________________________________________________________________________________________
l_softmax (Dense) [null,3] 51 l_dropout[0][0]
==================================================================================================
Total params: 164585007
Trainable params: 189507
Non-trainable params: 164395500
__________________________________________________________________________________________________
在python中,以下对我来说非常有效:
model.predict([tensor1, tensor2])
我将不胜感激任何贡献。
谢谢!
错误说明了一切。
您传递给模型的张量数组不是模型预期的大小。
作为输入传递给模型的张量的形状不是模型所期望的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.