【发布时间】:2018-11-04 00:56:34
【问题描述】:
我正在尝试使用我自己的数据运行此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()
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 的地雷
我想我可以稍微改变一下我的图像尺寸来解决这个问题,但我想了解正在发生的事情以及如何避免它
【问题讨论】:
标签: python neural-network keras autoencoder