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=’relu’)(input_img)
encoded = Dense(64, activation=’relu’)(encoded)
encoded = Dense(32, activation=’relu’)(encoded)
decoded = Dense(64, activation=’relu’)(encoded)
decoded = Dense(128, activation=’relu’)(decoded)
decoded = Dense(784, activation=’sigmoid’)(decoded)
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
Building Autoencoders in Keras
To build an autoencoder, you need three things: an encoding function, a decoding function, and a distance function…
Please let me know if this explanation was helpful