【问题标题】:ValueError: All input arrays (x) should have the same number of samplesValueError:所有输入数组 (x) 应具有相同数量的样本
【发布时间】:2020-05-13 06:47:51
【问题描述】:

我的 (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(输入,目标,权重) 733 raise ValueError('所有输入数组 (x) 应该有' 734'相同数量的样本。得到数组形状:'+ --> 735 str([x.shape for x in inputs])) 第736章 737 raise ValueError('所有目标数组(y)都应该有'

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

有解决这种错误的方法吗?谢谢

【问题讨论】:

  • 首先,您有 2 个 x 输入和 3 个 y 输入。
  • 可以有不同数量的输入和输出。例如,2 个输入,1 个输出等。
  • 是的,但您尚未提供相关信息。

标签: python tensorflow keras deep-learning multiple-input


【解决方案1】:

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

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

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

【讨论】:

    猜你喜欢
    • 2018-07-10
    • 2020-06-13
    • 1970-01-01
    • 2016-12-15
    • 1970-01-01
    • 2020-02-16
    • 2020-08-31
    • 2023-03-10
    • 2019-05-30
    相关资源
    最近更新 更多