官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 铁岭市| 禄丰县| 泸州市| 昌黎县| 苗栗市| 西青区| 兴和县| 多伦县| 日照市| 锡林浩特市| 讷河市| 邻水| 澎湖县| 衡阳市| 辰溪县| 麻阳| 西青区| 丰原市| 铜川市| 正定县| 牡丹江市| 东台市| 鄂伦春自治旗| 抚顺县| 建平县| 鄯善县| 隆尧县| 沙河市| 红原县| 新巴尔虎右旗| 河北区| 岳阳市| 香河县| 思茅市| 渭南市| 湄潭县| 固安县| 林周县| 潜山县| 息烽县| 慈利县|