Define an autoencoder with two Dense layers: an encoder , which compresses the images into a 64 dimensional latent vector, and a decoder , that reconstructs the original image from the latent space. To define your model, use the Keras Model Subclassing API .