Stack Exchange
How to separate the autoencoder model into encoder model and decoder model?
l am now trying to do some job in picture compression through DAE. l want to separate the trained autoencoder into encoder and decoder but l met some error.
Here is my code:
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))

And the error is:  

ValueError: Input 0 is incompatible with layer conv2d_10: expected axis -1 of input shape to have value 64 but got shape (None, 8, 8, 4)  

What should l do to fix the  error？ Thanks a lot!

l'm really anxious about the error.....Thanks a lot for your help!
