【问题标题】:Error when checking target: expected concatenate_1 to have shape (1,) but got array with shape (851,)检查目标时出错:预期 concatenate_1 的形状为 (1,) 但得到的数组的形状为 (851,)
【发布时间】:2019-08-02 07:28:10
【问题描述】:

我对 keras 连接有一些尺寸问题。似乎模型的输出数组(无,851)与错误消息中要求的维度不同。这是我得到的:

input_img = Input(shape=(32, 100, 1))

conv1 = Conv2D(filters = 64, kernel_size=(5, 5), strides=1, padding="same", activation="relu")(input_img)
maxpool1 = MaxPooling2D(pool_size=(2, 2), strides=None, padding='valid', data_format=None)(conv1)

conv2 = Conv2D(filters = 128, kernel_size=(5, 5), strides=1, padding="same", activation="relu")(maxpool1)
maxpool2 = MaxPooling2D(pool_size=(2, 2), strides=None, padding='valid', data_format=None)(conv2)

conv3 = Conv2D(filters = 256, kernel_size=(3, 3), strides=1, padding="same", activation="relu")(maxpool2)
maxpool3 = MaxPooling2D(pool_size=(2, 2), strides=None, padding='valid', data_format=None)(conv3)

conv4 = Conv2D(filters = 512, kernel_size=(3, 3), strides=1, padding="same", activation="relu")(maxpool3)
conv5 = Conv2D(filters = 512, kernel_size=(3, 3), strides=1, padding="same", activation="relu")(conv4)
flat1 = Flatten(data_format=None)(conv5)
dense1 = Dense(units = 4096, activation = "relu")(flat1)
dense2 = Dense(units = 4096)(dense1)

towers = [Dense(units = 37, activation='softmax')(dense2) for i in range (23)]
output = concatenate(towers, axis = -1)

char = Model(input=input_img, output=output)

Here is the summary the model

当我尝试拟合我的模型时,我收到以下消息: ValueError: 检查目标时出错:预期 concatenate_1 的形状为 (1,) 但得到的数组的形状为 (851,)

我不明白为什么 concatenate_1 应该具有形状 (1,) 而不是 (851,) 或 (None,851) 我的 target_train 的大小是 (867, 851),所以 .

有人遇到过这种错误吗?

非常感谢

【问题讨论】:

    标签: python keras keras-layer


    【解决方案1】:

    问题在于您的target_train,即您打算学习的所需输出。网络在串联后有 23*37 -> 851,总结为 (None, 851) 其中None 是动态批量大小。

    您需要调查如何将target_train 传递给.fit 函数。模型输出为 851,但训练循环给出了 1 个目标。

    【讨论】:

      猜你喜欢
      • 2018-08-29
      • 2019-07-07
      • 2020-09-03
      • 2020-03-13
      • 2020-05-19
      • 2019-01-16
      • 2019-01-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多