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 网站上的 example 说它应该可以工作。

我定义输入如下:

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 of samples. Got array shapes: ' + --> 735 str([x.shape for x in inputs])) 736 if len(set_y) > 1: 737 raise ValueError('All target arrays (y) should have '

ValueError: All input arrays (x) should have the same number of samples. Got array shapes: [(943, 1682), (1682, 943)]

有解决此类错误的方法吗?谢谢

我找到了这个问题的解决方案。输入的 length 必须相同。所以,我修改输入数据到相同的长度,以及输出。

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

The shape of input1 can be (1682, 943)
The shape of input2 should be (1682, 1682)