Now that we have a mechanism implemented to sample from the latent space, we can proceed to build a decoder capable of mapping this sample to the output space, thereby generating a novel instance of the input data. Recall that just as the encoder funnels the data by narrowing the layer dimensions till the encoded representation is reached, the decoder layers progressively enlarge the representations sampled from the latent space, mapping them back to the original image dimension:
#Decoder module
decoder_h= Dense(intermediate_dim, activation='relu')
decoder_mean= Dense(original_dim, activation='sigmoid')
h_decoded=decoder_h(z)
x_decoded_mean=decoder_mean(h_decoded)