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

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.

主站蜘蛛池模板: 轮台县| 清水县| 铜梁县| 自贡市| 新干县| 金溪县| 观塘区| 广丰县| 彭州市| 克拉玛依市| 兴仁县| 黑河市| 安平县| 南召县| 平利县| 维西| 宁武县| 白河县| 拉萨市| 武定县| 绥德县| 裕民县| 浦北县| 济宁市| 河源市| 安康市| 美姑县| 黔东| 上林县| 桐梓县| 上犹县| 耿马| 西和县| 邵阳市| 罗源县| 合水县| 当阳市| 沈阳市| 扶绥县| 和龙市| 永清县|