0

我的(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'相同的数字样本数。得到数组形状:' + --> 735 str([x.shape for x in inputs])) 736 if len(set_y) > 1: 737 raise ValueError('All target arrays (y) should have '

ValueError:所有输入数组 (x) 应具有相同数量的样本。得到数组形状:[(943, 1682), (1682, 943)]

有什么解决方案可以解决这种错误?谢谢

4

1 回答 1

0

我找到了解决这个问题的方法。它是输入的长度必须相同。因此,我将输入数据以及输出修改为相同的长度。

例如:我通过预处理数据将两个输入的长度设置为 1682。

The shape of input1 can be (1682, 943)
The shape of input2 should be (1682, 1682)
于 2020-01-27T22:32:09.647 回答