簡體   English   中英

如何將幾個張量傳遞給 tensorflow.js 中的 model.predict

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM