Examining the output

Our final step this time around will be to see what is actually happening with the images. We will finish this exercise by outputting a small sample of images in order to get our success rate. Follow along in the next exercise in order to finish the code and run the autoencoder:

  1. Continuing from the last exercise, locate the following last section of code:
import matplotlib.pyplot as plt
n = 10 # how many digits we will display
plt.figure(figsize=(20, 4))
for i in range(n):
# display original
ax = plt.subplot(2, n, i + 1)
plt.imshow(x_test[i].reshape(28, 28))
plt.gray()
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)

# display reconstruction
ax = plt.subplot(2, n, i + 1 + n)
plt.imshow(decoded_imgs[i].reshape(28, 28))
plt.gray()
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
plt.show()
  1. In this section of code, we are just outputting the input and resultant auto-encoded images after all the training is done. This section of code starts with importing mathplotlib for plotting, and then we loop through a number of images to display the results. The rest of the code just outputs the images.
  2. Run the Python code as you normally would, and this time expect the training to take several minutes. After everything is done, you should see an image similar to the following:
Example of raw input images compared to encoded and decoded output images

That completes our look into building a simple Keras model that can encode and then decode images. This allows us to see how each small piece of a multilayer neural network is written in Keras functions. In the final section, we invite you, the reader, to undertake some additional exercises for further learning.

..................Content has been hidden....................

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