【问题标题】:Why does Keras documentation examples for autonencoders use Conv2D instead of Conv2DTranspose为什么自动编码器的 Keras 文档示例使用 Conv2D 而不是 Conv2DTranspose
【发布时间】:2020-05-06 01:58:04
【问题描述】:

我一直在关注 Keras 文档来构建 CNN 自动编码器 https://blog.keras.io/building-autoencoders-in-keras.html.

from keras.layers import Input, Dense, Conv2D, MaxPooling2D, UpSampling2D
from keras.models import Model
from keras import backend as K

input_img = Input(shape=(28, 28, 1))  # adapt this if using `channels_first` image data format

x = Conv2D(16, (3, 3), activation='relu', padding='same')(input_img)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
encoded = MaxPooling2D((2, 2), padding='same')(x)

# at this point the representation is (4, 4, 8) i.e. 128-dimensional

x = Conv2D(8, (3, 3), activation='relu', padding='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Conv2D(8, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
x = Conv2D(16, (3, 3), activation='relu')(x)
x = UpSampling2D((2, 2))(x)
decoded = Conv2D(1, (3, 3), activation='sigmoid', padding='same')(x)

autoencoder = Model(input_img, decoded)
autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')

我注意到它在解码层中使用了 Conv2D 而不是 Conv2DTranspose。但是其他一些文章解释了使用 Conv2DTranspose 代替 Upsampling2D 和 Conv2D 的 CNN 自动编码器。我见过几个与 Conv2DTranspose 本身相关的问题。但是我还没有找到我的问题的答案。

我的问题是我可以使用 Conv2DTranspose 代替 Upsampling2D 和 Conv2D 层。如果是这样,为什么作者自己(Keras 文档)没有使用它?有什么区别吗?

【问题讨论】:

    标签: keras conv-neural-network autoencoder tf.keras deconvolution


    【解决方案1】:

    转置卷积通常会导致称为Checkerboard artifacts 的伪影 - 相邻的小方块很容易相互区分。这些使人类很容易从真实图像中识别出假图像。

    您可以阅读this article了解更多信息。

    简而言之,使用Resizing + Conv2D 而不是Conv2dTranspose 可以最大限度地减少这些棋盘伪影。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-07
      • 1970-01-01
      • 2018-03-10
      • 1970-01-01
      • 2019-09-19
      • 2017-07-19
      • 2020-04-18
      • 2015-11-21
      相关资源
      最近更新 更多