Please see the following blog post for more details about this code Understanding Autoencoders using Tensorflow (Python)