In this section, we'll see how a VAE can generate new digits for the MNIST dataset and we'll use Keras to do so. We chose MNIST because it will illustrate the generative capabilities of the VAE well. Let's start:
- Do the imports:
import matplotlib.pyplot as pltfrom matplotlib.markers import MarkerStyleimport numpy as npfrom keras import backend as Kfrom keras.datasets import mnistfrom keras.layers import Lambda, Input, Densefrom keras.losses import binary_crossentropyfrom keras.models import Model
- Instantiate the MNIST dataset (we've already done that):
(x_train, y_train), (x_test, y_test) = mnist.load_data()image_size = x_train.shape * x_train.shapex_train = np.reshape(x_train, [-1, image_size]) ...