Good question Chris.

The reason why we don’t use the same neural network that we used for encoding to decode is

  • To predict the output and compare it with the input data to calculate the loss. The output layer needs to predict the probability of an output which needs to either 0 or 1 and hence we use sigmoid activation function.
  • Hidden layers for the encoder and decoder uses relu activation function as we want non linearity.

A sample code for AE would be something like this

input_img = Input(shape=(784,))
encoded = Dense(128, activation=’
encoded = Dense(64, activation=’
encoded = Dense(32, activation=’

decoded = Dense(64, activation=’relu’)(encoded)
decoded = Dense(128, activation=’
decoded = Dense(784, activation=’

Autoencoders are used to extract the latent feature representation so we also store the latent feature into a pickle file

I also plan to post AE code this week

For more on the AE refer to

Please let me know if this explanation was helpful

Loves learning, sharing, and discovering myself. Passionate about Machine Learning and Deep Learning

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store