Python 如何将自动编码器模型分为编码器模型和解码器模型?

Python 如何将自动编码器模型分为编码器模型和解码器模型?,python,encoding,Python,Encoding,我现在正试图通过DAE做一些图片压缩的工作。我想把经过训练的自动编码器分为编码器和解码器,但我遇到了一些错误。 这是我的密码: input_img = Input(shape=(32,32,3)) x = Convolution2D(64, 3, 3, activation='relu', border_mode='same')(input_img) x = AveragePooling2D((2, 2))(x) x = Convolution2D(32, 3, 3, activation='r

我现在正试图通过DAE做一些图片压缩的工作。我想把经过训练的自动编码器分为编码器和解码器,但我遇到了一些错误。
这是我的密码:

input_img = Input(shape=(32,32,3))
x = Convolution2D(64, 3, 3, activation='relu', border_mode='same')(input_img)
x = AveragePooling2D((2, 2))(x)
x = Convolution2D(32, 3, 3, activation='relu', border_mode='same')(x)
x = AveragePooling2D((2, 2))(x)
x = Convolution2D(16, 3, 3, activation='relu', border_mode='same')(x)
x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)
encoded = Convolution2D(4, 3, 3, activation='sigmoid', border_mode='same'(x)
    #decoder
x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(encoded)
x = Convolution2D(16, 3, 3, activation='relu', border_mode='same')(x)
x = UpSampling2D((2, 2))(x)
x = Convolution2D(32, 3, 3, activation='relu', border_mode='same')(x)
x = UpSampling2D((2, 2))(x)
x = Convolution2D(64, 3, 3, activation='relu',border_mode='same')(x)
decoded = Convolution2D(3, 3, 3, activation='sigmoid', border_mode='same'(x)
autoencoder =Model(input_img,decoded)
encoder=Model(input_img,encoded)
encoded_input=Input(shape=(8,8,4))
decoder_layer = autoencoder.layers[-1]
print (np.array(decoder_layer).shape)
decoder = Model(encoded_input,decoder_layer(encoded_input))
错误是:

ValueError:输入0与层conv2d_10不兼容:输入形状的轴-1应具有值64,但得到形状(无、8、8、4)


我该怎么做才能纠正错误?非常感谢

我真的很担心这个错误…非常感谢你的帮助!