Keras 如何使解码器输出形状与输入图像形状相等?
我试图找出:Keras 如何使解码器输出形状与输入图像形状相等?,keras,conv-neural-network,autoencoder,Keras,Conv Neural Network,Autoencoder,我试图找出:解码器。output\u shape[1::==IMG\u shape 我有以下我已编程的功能。当我尝试运行解码器.output_shape[1::==IMG_shape时,我发现我的图像形状和解码器输出形状不一样 def build_deep_autoencoder(img_shape, code_size): """PCA's deeper brother.""" H,W,C = img_shape # encoder encoder = ker
解码器。output\u shape[1::==IMG\u shape
我有以下我已编程的功能。当我尝试运行解码器.output_shape[1::==IMG_shape时,我发现我的图像形状和解码器输出形状不一样
def build_deep_autoencoder(img_shape, code_size):
"""PCA's deeper brother."""
H,W,C = img_shape
# encoder
encoder = keras.models.Sequential()
encoder.add(L.InputLayer(img_shape))
# numbers of output channels: 32, 64, 128, 256.
encoder.add(L.Conv2D(filters=32, kernel_size=(3, 3), padding='same', activation='elu'))
encoder.add(L.MaxPooling2D())
encoder.add(L.Conv2D(filters=64, kernel_size=(3, 3), padding='same', activation='elu'))
encoder.add(L.MaxPooling2D())
encoder.add(L.Conv2D(filters=128, kernel_size=(3, 3), padding='same', activation='elu'))
encoder.add(L.MaxPooling2D())
encoder.add(L.Conv2D(filters=256, kernel_size=(3, 3), padding='same', activation='elu'))
encoder.add(L.MaxPooling2D())
encoder.add(L.Flatten()) #flatten image to vector
encoder.add(L.Dense(code_size, activation = 'elu'))
# decoder
decoder = keras.models.Sequential()
decoder.add(L.InputLayer((code_size,)))
# numbers of output channels: 128, 64, 32, 3.
decoder.add(L.Dense(np.prod(img_shape), activation = 'elu')) #actual decoder, height*width*3 units
decoder.add(L.Reshape(img_shape)) #un-flatten
decoder.add(L.Conv2DTranspose(filters=128, kernel_size=(3, 3), strides=2, activation='elu', padding='same'))
decoder.add(Conv2DTranspose(filters=64, kernel_size=(3, 3), strides=2, activation='elu', padding='same'))
decoder.add(L.Conv2DTranspose(filters=32, kernel_size=(3, 3), strides=2, activation='elu', padding='same'))
decoder.add(L.Conv2DTranspose(filters=3, kernel_size=(3, 3), strides=2, activation=None, padding='same'))
return encoder, decoder
请注意,code\u size=32
我希望解码器的输出。output_shape[1::==IMG_shape
为True
,但实际输出为False