Keras 自动编码器的输入和输出层不匹配,无法 运行 建模
Input and output layers of Keras autoencoder don't match, can't run model
我正尝试在 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)
我正尝试在 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)