We are going to use three auxiliary functions to get the data, plot the images, and plot the losses.
The function to get the data uses the Keras cifar10 class, converts it to fp32, 32-bit floating point, and scales it to [-1, 1]. Scaling images to [-1, 1] is a common practice when training GANs on image data that bounds the range of the output, possibly avoiding explosions:
def get_data():
# load cifar10 data
(X_train, y_train), (X_test, y_test) = cifar10.load_data()
# convert train and test data to float32
X_train = X_train.astype(np.float32)
X_test = X_test.astype(np.float32)
# scale train and test data to [-1, 1]
X_train = (X_train / 255) * 2 - 1
X_test = (X_train / 255) * 2 - 1
return X_train, X_test
The method below is used to plot a grid with images. It takes a tensor with the images and the full path where the image...