How to separately use the encoder of an Autoencoder in keras?
<p>I have trained the following autoencoder model:</p>

<pre><code>input_img = Input(shape=(1, 32, 32))

x = Convolution2D(16, 3, 3, activation='relu', border_mode='same')(input_img)
x = MaxPooling2D((2, 2), border_mode='same')(x)
x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)
x = MaxPooling2D((2, 2), border_mode='same')(x)
x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)
encoded = MaxPooling2D((2, 2), border_mode='same')(x)


x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(encoded)
x = UpSampling2D((2, 2))(x)
x = Convolution2D(8, 3, 3, activation='relu', border_mode='same')(x)
x = UpSampling2D((2, 2))(x)
x = Convolution2D(16, 3, 3, activation='relu',border_mode='same')(x)
x = UpSampling2D((2, 2))(x)
decoded = Convolution2D(1, 3, 3, activation='sigmoid', border_mode='same')(x)

autoencoder = Model(input_img, decoded)
autoencoder.compile(optimizer='RMSprop', loss='binary_crossentropy')

autoencoder.fit(X_train, X_train,
            nb_epoch=1,
            batch_size=128,
            shuffle=True,
            validation_data=(X_test, X_test)]
            )
</code></pre>

<p>After training this autoencoder i want to use the trained encoder for a supervised line. How can i extract only the trained encoder part of this autoencoder model ? </p>

<p>You can just create a model after training that only uses the encoder:</p>

<pre><code>autoencoder = Model(input_img, encoded)
</code></pre>

<p>If you want to add further layers after the encoded portion, you can do that as well:</p>

<pre><code>classifier = Dense(nb_classes, activation='softmax')(encoded)
model = Model(input_img, classifier)
</code></pre>

python neural-network deep-learning keras autoencoder