【问题标题】:Keras Convolutional Autoencoder: Layer ShapesKeras 卷积自动编码器:图层形状
【发布时间】:2017-01-04 01:14:45
【问题描述】:

我有一个包含大约 70,000 张训练图像的列表,每个形状(颜色通道数,高度宽度)= (3, 30, 30),以及大约 20,000 张测试图像。我的卷积自动编码器定义为:

 # Same as the code above, but with some params changed
# Now let's define the model. 

# Set input dimensions:
input_img = Input(shape=(3, 30, 30))

# Encoder: define a chain of Conv2D and MaxPooling2D layers
x = Convolution2D(128, 3, 3, 
                  activation='relu', 
                  border_mode='same')(input_img)
x = MaxPooling2D((2, 2), border_mode='same')(x)
x = Convolution2D(64, 3, 3, 
                  activation='relu', 
                  border_mode='same')(x)
x = MaxPooling2D((2, 2), border_mode='same')(x)
x = Convolution2D(64, 3, 3, 
                  activation='relu', 
                  border_mode='same')(x)
encoded = MaxPooling2D((2, 2), border_mode='same')(x)

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

# Decoder: a stack of Conv2D and UpSampling2D layers
x = Convolution2D(64, 3, 3, 
                  activation='relu', 
                  border_mode='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Convolution2D(64, 3, 3, 
                  activation='relu', 
                  border_mode='same')(x)
x = UpSampling2D((2, 2))(x)
x = Convolution2D(128, 3, 3, 
                  activation='relu')(x)
x = UpSampling2D((2, 2))(x)
decoded = Convolution2D(1, 3, 3, 
                        activation='sigmoid', 
                        border_mode='same')(x)

autoencoder2 = Model(input_img, decoded)
autoencoder2.compile(optimizer='adadelta', loss='mse')

这是来自here 的自动编码器。

它会抛出一个错误:

Error when checking model target: expected convolution2d_14 to have shape (None, 1, 28, 28) but got array with shape (76960, 3, 30, 30)

这很奇怪,因为我已经清楚地将指定的输入形状更改为 (3, 30, 30)。我是否缺少一些实现技术性?

【问题讨论】:

标签: python keras autoencoder


【解决方案1】:

您忘记在解码器的最后一个卷积层中添加border_mode='same'。

【讨论】:

    【解决方案2】:

    https://blog.keras.io/building-autoencoders-in-keras.html,他们忘记添加了

    'border_mode='same''.

    例如,在您的倒数第二个卷积层中;

    x = Convolution2D(128, 3, 3, activation='relu')(x)

    【讨论】:

      【解决方案3】:

      您应该将最后一个卷积层的形状从 (1,3,3) 更改为 (3,3,3),如下所示:

      decoded = Convolution2D(3, 3, 3, 
                          activation='sigmoid', 
                          border_mode='same')(x)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-11-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-11
        • 1970-01-01
        • 2020-08-20
        相关资源
        最近更新 更多