【发布时间】:2020-03-16 19:56:50
【问题描述】:
我正在尝试使用 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 个张量。
model.summary():
__________________________________________________________________________________________________
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])
我会感谢任何贡献。
谢谢!
【问题讨论】:
-
能否将 model.summary() 添加到您的问题中?
标签: javascript tensorflow model predict tensorflow.js