简体   繁体   English

如何将几个张量传递给 tensorflow.js 中的 model.predict

[英]how to pass several tensor to a model.predict in tensorflow.js

I'm trying to use tensorflow.js to run a model that I created in python.我正在尝试使用 tensorflow.js 来运行我在 python 中创建的模型。 This model has two inputs tensor, one of [1, 60] shape and another of [1, 60, 1].该模型有两个输入张量,一个是 [1, 60] 形状,另一个是 [1, 60, 1]。 I'm doing this:我这样做:

    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]);

But it's giving me this message:但它给了我这个信息:

Error: Error when checking model : the Array of Tensors that you are passing to your model is not the size the the model expected.错误:检查模型时出错:您传递给模型的张量数组不是模型预期的大小。 Expected to see 2 Tensor(s), but instead got 1 Tensors(s).预计会看到 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
__________________________________________________________________________________________________

In python, the following works perfectly for me:在python中,以下对我来说非常有效:

    model.predict([tensor1, tensor2])

I will appreciate any contribution.我将不胜感激任何贡献。

Thank you!谢谢!

The error says it all.错误说明了一切。

the Array of Tensors that you are passing to your model is not the size the the model expected.您传递给模型的张量数组不是模型预期的大小。

The shape of the tensors passed as inputs to the models is not what the model expects作为输入传递给模型的张量的形状不是模型所期望的

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

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