Plot the Training - 2

Let's define another function which plots the images generated during each epoch. To reflect the difference, we also include the original and the masked/noised images in the plot.  A sample output of this function is shown below after the code snippet.

The top row contains the original images,  the middle row contain the masked images, and the bottom row contains the generated images.

The plot has 12 rows with the following sequence.  row1 -original, row 2 - masked, row3 - generated, row 4 - original, row5 - masked,......., row 12 - generated.

def plot_generated_images_combined(original, noised_data, generator):
rows, cols = 4, 12
num = rows * cols
image_size = 28

generated_images = generator.predict(noised_data[0:num])

imgs = np.concatenate([original[0:num], noised_data[0:num], generated_images])
imgs = imgs.reshape((rows * 3, cols, image_size, image_size))
imgs = np.vstack(np.split(imgs, rows, axis=1))
imgs = imgs.reshape((rows * 3, -1, image_size, image_size))
imgs = np.vstack([np.hstack(i) for i in imgs])
imgs = upscale(imgs)
plt.figure(figsize=(8,16))
plt.axis('off')
plt.title('Original Images: top rows, '
'Corrupted Input: middle rows, '
'Generated Images: bottom rows')
plt.imshow(imgs, cmap='gray')
plt.show()
Figure 14.10: Sample/Expected output from the 'plot_generated_images_combined' function
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset