可视化重建
确保自编码器得到适当训练的一种方法是比较输入和输出。 它们必须非常相似,差异应该是不重要的细节。 我们来绘制两个随机数字及其重建:
n_test_digits = 2X_test = mnist.test.images[:n_test_digits]with tf.Session() as sess:[...] # Train the Autoencoderoutputs_val = outputs.eval(feed_dict={X: X_test})def plot_image(image, shape=[28, 28]):plt.imshow(image.reshape(shape), cmap="Greys", interpolation="nearest")plt.axis("off")for digit_index in range(n_test_digits):plt.subplot(n_test_digits, 2, digit_index * 2 + 1)plot_image(X_test[digit_index])plt.subplot(n_test_digits, 2, digit_index * 2 + 2)plot_image(outputs_val[digit_index])

看起来够接近。 所以自编码器已经适当地学会了重现它,但是它学到了有用的特性? 让我们来看看。
