Advertisement
Guest User

MNIST Image Viewer

a guest
Jan 13th, 2017
444
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.68 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import tensorflow as tf
  4. from tensorflow.examples.tutorials.mnist import input_data
  5. import matplotlib.pyplot as plt
  6. import numpy as np
  7.  
  8. mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)
  9.  
  10. def image(imnumber):
  11.     a = mnist.train.images[imnumber,0:784]
  12.     b = np.fliplr(a.reshape((28,28)))
  13.     c = mnist.train.labels[imnumber]
  14.     x = np.linspace(imnumber,28,28)
  15.     y = x
  16.     print 'Label:',int(np.nonzero(c)[0])
  17.     plt.pcolormesh(x,y,b,cmap='Greys')
  18.     plt.show()
  19.  
  20. print 'Enter -1 to exit'
  21. while(True):
  22.     print ''
  23.     imnumber = int(raw_input('Enter Image Number: '))
  24.     if(imnumber==-1):
  25.         break
  26.    
  27.     image(imnumber)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement