【问题标题】:Uexpected output dimension in keras cnn networkkeras cnn网络中的​​超预期输出维度
【发布时间】:2017-04-11 23:00:07
【问题描述】:

由于某种原因,我的分类网络得到了一个出乎意料的输出维度。

网络有 18 个形状为 (45,5,3) 的输入

输出是一个长度为 15 的向量 - 每 45 个类别对应一个类别。提取的类别来自 145 个类别的池。

我的网络如下所示:

#stride = 2
#dim = 40
#window_height = 5
#splits = ((40-5)+1)/2 = 18

kernel_number = int(math.ceil(splits))
list_of_input = [Input(shape = (45,5,3)) for i in range(splits)]
list_of_conv_output = []
list_of_max_out = []
for i in range(splits):
    list_of_conv_output.append(Conv2D(filters = kernel_number , kernel_size = (int(splits-3),3))(list_of_input[i]))
    list_of_max_out.append((MaxPooling2D(pool_size=((2,2)))(list_of_conv_output[i])))

merge = keras.layers.concatenate(list_of_max_out)
print merge.shape
reshape = Reshape((15,324))(merge)

dense1 = Dense(units = 1000, activation = 'relu',    name = "dense_1")(reshape)
dense2 = Dense(units = 1000, activation = 'relu',    name = "dense_2")(dense1)
dense3 = Dense(units = 145 , activation = 'softmax', name = "dense_3")(dense2)
model = Model(inputs = list_of_input ,outputs = dense3)

但由于某种原因,当我传递输出数据时出现错误。 它当前存储为形状 (16828,15) 的 numpy.ndarray,我收到一个值错误说明:

Error when checking model target: expected dense_3 to have 3 dimensions, but got array with shape (16828, 15)

为什么预期是 3 暗而不是 2 暗?

模型摘要表明输出暗淡为 (15,145),正如我所期望的那样? 145 个班级中的 15 个班级。或者这是不正确的?

型号总结: https://pastebin.com/27YTQW2m

【问题讨论】:

  • print merge.shape 的结果是什么?
  • @Van (?, 15, 1, 324)
  • 你的输出数组存储的是什么?整数?你的loss 功能是什么?
  • 还没有决定关于损失的任何事情......所以将尝试使用 SGD,从那里看到......但是带有类的向量。

标签: python numpy keras


【解决方案1】:

如果我被纠正了,model.output_shape(None, 15, 145),并且您在训练期间发送了一个形状为 (16828, 15) 的数组。

您可能希望在安装之前将(16828, 15) 扩展为(16828, 15, 145)

【讨论】:

    猜你喜欢
    • 2017-06-08
    • 2016-12-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-30
    • 2021-09-08
    • 1970-01-01
    相关资源
    最近更新 更多