Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "visualizing output in autoencoder" #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 2 additions & 28 deletions 06_autoencoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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')