【问题标题】:Resize Output Layer in Keras Python在 Keras Python 中调整输出层的大小
【发布时间】:2019-11-17 16:29:14
【问题描述】:

我的目标是将输出图像的大小从 [32,32,1] 调整为 [8,8,1]

我尝试使用 reshape 进行此操作,但出现错误:

Output_model = Reshape((8,8,-1))(out_1)
Error when checking target: expected reshape_1 to have shape (8, 8, 32) but got array with shape (32, 32, 1)

我该如何解决这个问题??

非常感谢

【问题讨论】:

    标签: python keras resize reshape


    【解决方案1】:

    您不能直接对数组进行整形,因为 32*32*1 不等于 8*8*1,因此您必须进行二次采样:

    import keras
    x=keras.layers.Input((32,32,1))
    x=keras.layers.MaxPooling2D((4,4))(x)
    

    然后您的图像将下采样到 (8,8,1)。

    【讨论】:

    • 感谢您的回答。其作品。但现在我有以下错误:检查目标时出错:预期 max_pooling2d_5 的形状为 (8, 8, 1) 但得到的数组形状为 (32, 32, 1)
    • 你能写一个小代码重现错误吗?
    • 这个小代码很难写,因为我的代码很复杂。我可以尝试解释错误:我将图像数据集设置为 Keras.generator 并编译我的模型。这行得通。我看到输入(32x32),层和我的输出(8x8)。然后我等待 30-40 秒,我的 IDE 在拟合函数期间绘制错误:ValueError:检查目标时出错:预期 max_pooling2d_5 具有形状(8、8 , 1) 但得到了形状为 (32, 32, 1) 的数组
    • 你至少能写出网络图的代码吗?
    • 我在描述中添加了我的架构
    猜你喜欢
    • 2017-07-04
    • 1970-01-01
    • 2018-07-30
    • 1970-01-01
    • 1970-01-01
    • 2017-06-13
    • 1970-01-01
    • 2020-02-09
    • 1970-01-01
    相关资源
    最近更新 更多