Keras 自动编码器的输入层和输出层不匹配,无法运行模型



我正在尝试在 Keras 中构建一个自动编码器,输入形状为 (470,470,3(,但输出似乎永远不匹配,即使我尝试切换填充。这是我的代码,你能帮忙吗?目前编写的方式,我的模型摘要显示输出为 (472, 472, 3(。

from tensorflow.keras.layers import Conv2D, MaxPooling2D, UpSampling2D
from tensorflow.keras import Input, Model
input_image = Input(shape=(470, 470, 3)) 
x = Conv2D(32, (3, 3), activation='relu', padding='same')(input_image)
x = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(32, (3, 3), activation='relu', padding='same')(x)
encoded = MaxPooling2D((2, 2), padding='same')(x)
x = Conv2D(32, (3, 3), activation='relu', padding='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Conv2D(32, (3, 3), activation='relu', padding='same')(x)
x = UpSampling2D((2, 2))(x)
decoded_image = Conv2D(3, (3, 3), activation='sigmoid', padding='same')(x)
autoencoder = Model(input_image, decoded_image)
autoencoder.compile(optimizer='adadelta', loss='binary_crossentropy')

谢谢!

将最后一个填充更改为'valid'

decoded_image = Conv2D(3, (3, 3), activation='sigmoid', padding='valid')(x)

相关内容

  • 没有找到相关文章

最新更新