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

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.

主站蜘蛛池模板: 宁蒗| 伊宁县| 永仁县| 苏尼特右旗| 灵武市| 朝阳区| 定安县| 铅山县| 阜平县| 芮城县| 吉木乃县| 绥德县| 黄石市| 阿克| 新野县| 若羌县| 八宿县| 柏乡县| 平遥县| 抚远县| 台东市| 馆陶县| 台中市| 邢台县| 高碑店市| 潜江市| 昆明市| 都兰县| 十堰市| 宣恩县| 肇州县| 伊金霍洛旗| 淳安县| 澳门| 金川县| 舒兰市| 岳西县| 商水县| 金湖县| 额尔古纳市| 清河县|