我正在尝试使用自己的数据运行这个convolutional auto encoder示例,所以我根据我的图像修改了它的InputLayer。然而,在输出层上,尺寸有一个问题。我确信问题出在UpSampling上,但我不确定为什么会发生这种情况:下面是代码。
N, H, W = X_train.shape
input_img = Input(shape=(H,W,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')
autoencoder.summary()

然后,当我运行fit时,抛出这个错误:
i+=1
autoencoder.fit(x_train, x_train,
epochs=50,
batch_size=128,
shuffle=True,
validation_data=(x_test, x_test),
callbacks= [TensorBoard(log_dir='/tmp/autoencoder/{}'.format(i))])
ValueError: Error when checking target: expected conv2d_23 to have shape (148, 84, 1) but got array with shape (150, 81, 1)我返回到教程代码,并尝试查看其模型的摘要,它显示了以下内容:

我肯定在解码器上重建输出时会有问题,但我不确定为什么,为什么它适用于128x28图像,而不适用于150x81的图像
我想我可以稍微改变我的图像的维度来解决这个问题,但我想了解发生了什么,以及如何避免它
发布于 2019-08-30 15:36:02
解码器的最后一层不使用任何填充。您可以通过将解码器中的最后一层更改为:
x = Conv2D(16, (3, 3), activation='relu', padding='same')(x)您将看到输出暗淡现在将与输入暗淡相匹配。
https://stackoverflow.com/questions/50515409
复制相似问题