![](/img/trans.png)
[英]model.fit() generates ERROR: ValueError: All input arrays (x) should have the same number of samples
[英]ValueError: All input arrays (x) should have the same number of samples
我的(Keras)模型有兩個不同形狀的輸入。 Keras 網站上的示例說它應該可以工作。
我將輸入定義如下:
model1 = Model(inputs=[uii, vji], outputs=[decoded,decoded2, prod])
model1.summary()
Model: "model_10"
__________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
==================================================================================================
input_49 (InputLayer) [(None, 1682)] 0
__________________________________________________________________________________________________
input_51 (InputLayer) [(None, 943)] 0
__________________________________________________________________________________________________
但是當擬合模型時:
model1.fit([matrix, matrix.T], [matrix, matrix.T,matrix.reshape(-1)])
它產生以下錯誤:
/tensorflow-2.1.0/python3.6/tensorflow_core/python/keras/engine/training_utils.py in check_array_lengths(inputs, targets, weights) 733 raise ValueError('All input arrays (x) should have '734' the same number樣本數。得到數組形狀:' + --> 735 str([x.shape for x in input])) 736 if len(set_y) > 1: 737 raise ValueError('All target arrays (y) should have '
ValueError:所有輸入數組 (x) 應具有相同數量的樣本。 得到數組形狀:[(943, 1682), (1682, 943)]
任何解決此類錯誤的解決方案? 謝謝
我找到了這個問題的解決方案。 它是輸入的長度必須相同。 因此,我將輸入數據和輸出修改為相同的長度。
例如:我通過預處理數據將兩個輸入的長度都設置為 1682。
The shape of input1 can be (1682, 943)
The shape of input2 should be (1682, 1682)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.