【问题标题】:Keras Conv2D decoderKeras Conv2D 解码器
【发布时间】:2020-01-05 13:02:46
【问题描述】:

我正在处理不同大小 (x,y) 的图像。在MaxPooling2D 之后使用UpSampling2D 时,它不能很好地重建它,因为x-dim 不等于y-dim。它在 x=y(例如 28x28)时有效,但在我的情况下(388x45)。我怎么解决这个问题。

input_img = Input(shape=(388, 45, 1))  

x = Conv2D(32, (3, 3), activation='relu', padding='same')(input_img)
x = MaxPooling2D((2, 2), padding='same')(x)

x = UpSampling2D((2, 2))(x)
x = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)

【问题讨论】:

    标签: python machine-learning keras conv-neural-network


    【解决方案1】:

    解决方案是在上采样层之后添加ZeroPadding2D 以达到所需的形状。

    实际上,如果您有图像的形状 ((19,30)),为了获得偶数,例如,在第一个位置,您会添加:

    x = UpSampling2D((2, 2))(x) #say here the shape is (19,30) after upsampling but you need (20,30)
    x = ZeroPadding2D(((1, 0), (0, 0)))(x) # change to ZeroPadding2D(((0, 0), (0, 1))) if you want second dimension to increase by 1
    

    您可以在此答案中找到 ZeroPadding2D 的完美用法: segnet in keras: total size of new array must be unchanged error

    【讨论】:

      猜你喜欢
      • 2018-12-13
      • 2020-03-10
      • 1970-01-01
      • 2021-02-16
      • 1970-01-01
      • 2018-08-31
      • 1970-01-01
      • 2019-09-19
      • 2019-01-11
      相关资源
      最近更新 更多