From e4a4850dc4329b120a826038f5faed9779db741e Mon Sep 17 00:00:00 2001 From: Sung Kim Date: Tue, 18 Oct 2016 13:28:39 +0800 Subject: [PATCH] Revert "visualizing output in autoencoder" --- 06_autoencoder.py | 30 ++---------------------------- 1 file changed, 2 insertions(+), 28 deletions(-) diff --git a/06_autoencoder.py b/06_autoencoder.py index a78002c..5781a23 100644 --- a/06_autoencoder.py +++ b/06_autoencoder.py @@ -2,25 +2,6 @@ import numpy as np import input_data -import matplotlib # to plot images -# Force matplotlib to not use any X-server backend. -matplotlib.use('Agg') -import matplotlib.pyplot as plt -import matplotlib.gridspec as gridspec - -## Visualizing reconstructions -def vis(images, save_name): - dim = images.shape[0] - n_image_rows = int(np.ceil(np.sqrt(dim))) - n_image_cols = int(np.ceil(dim * 1.0/n_image_rows)) - gs = gridspec.GridSpec(n_image_rows,n_image_cols,top=1., bottom=0., right=1., left=0., hspace=0., wspace=0.) - for g,count in zip(gs,range(int(dim))): - ax = plt.subplot(g) - ax.imshow(images[count,:].reshape((28,28))) - ax.set_xticks([]) - ax.set_yticks([]) - plt.savefig(save_name + '_vis.png') - mnist_width = 28 n_visible = mnist_width * mnist_width n_hidden = 500 @@ -58,7 +39,7 @@ def model(X, mask, W, b, W_prime, b_prime): # create cost function cost = tf.reduce_sum(tf.pow(X - Z, 2)) # minimize squared error train_op = tf.train.GradientDescentOptimizer(0.02).minimize(cost) # construct an optimizer -predict_op = Z + # load MNIST data mnist = input_data.read_data_sets("MNIST_data/", one_hot=True) trX, trY, teX, teY = mnist.train.images, mnist.train.labels, mnist.test.images, mnist.test.labels @@ -76,11 +57,4 @@ def model(X, mask, W, b, W_prime, b_prime): mask_np = np.random.binomial(1, 1 - corruption_level, teX.shape) print(i, sess.run(cost, feed_dict={X: teX, mask: mask_np})) - # save the predictions for 100 images - mask_np = np.random.binomial(1, 1 - corruption_level, teX[:100].shape) - predicted_imgs = sess.run(predict_op, feed_dict={X: teX[:100], mask: mask_np}) - input_imgs = teX[:100] - # plot the reconstructed images - vis(predicted_imgs,'pred') - vis(input_imgs,'in') - print('Done') \ No newline at end of file +