In [1]:
from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf

In [2]:
flags = tf.app.flags
FLAGS = flags.FLAGS
flags.DEFINE_string('data_dir', './flagdata_dir/', 'Directory for storing data')

In [3]:
mnist = input_data.read_data_sets(FLAGS.data_dir, one_hot=True)


Extracting ./flagdata_dir/train-images-idx3-ubyte.gz
(60000, 28, 28, 1)
[[[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  3]
  [ 18]
  [ 18]
  [ 18]
  [126]
  [136]
  [175]
  [ 26]
  [166]
  [255]
  [247]
  [127]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [ 30]
  [ 36]
  [ 94]
  [154]
  [170]
  [253]
  [253]
  [253]
  [253]
  [253]
  [225]
  [172]
  [253]
  [242]
  [195]
  [ 64]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [ 49]
  [238]
  [253]
  [253]
  [253]
  [253]
  [253]
  [253]
  [253]
  [253]
  [251]
  [ 93]
  [ 82]
  [ 82]
  [ 56]
  [ 39]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [ 18]
  [219]
  [253]
  [253]
  [253]
  [253]
  [253]
  [198]
  [182]
  [247]
  [241]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [ 80]
  [156]
  [107]
  [253]
  [253]
  [205]
  [ 11]
  [  0]
  [ 43]
  [154]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [ 14]
  [  1]
  [154]
  [253]
  [ 90]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [139]
  [253]
  [190]
  [  2]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [ 11]
  [190]
  [253]
  [ 70]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [ 35]
  [241]
  [225]
  [160]
  [108]
  [  1]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [ 81]
  [240]
  [253]
  [253]
  [119]
  [ 25]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [ 45]
  [186]
  [253]
  [253]
  [150]
  [ 27]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [ 16]
  [ 93]
  [252]
  [253]
  [187]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [249]
  [253]
  [249]
  [ 64]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [ 46]
  [130]
  [183]
  [253]
  [253]
  [207]
  [  2]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [ 39]
  [148]
  [229]
  [253]
  [253]
  [253]
  [250]
  [182]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [ 24]
  [114]
  [221]
  [253]
  [253]
  [253]
  [253]
  [201]
  [ 78]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [ 23]
  [ 66]
  [213]
  [253]
  [253]
  [253]
  [253]
  [198]
  [ 81]
  [  2]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [ 18]
  [171]
  [219]
  [253]
  [253]
  [253]
  [253]
  [195]
  [ 80]
  [  9]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [ 55]
  [172]
  [226]
  [253]
  [253]
  [253]
  [253]
  [244]
  [133]
  [ 11]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [136]
  [253]
  [253]
  [253]
  [212]
  [135]
  [132]
  [ 16]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]

 [[  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]
  [  0]]]
Extracting ./flagdata_dir/train-labels-idx1-ubyte.gz
Extracting ./flagdata_dir/t10k-images-idx3-ubyte.gz
Extracting ./flagdata_dir/t10k-labels-idx1-ubyte.gz

In [4]:
print("train examples:", mnist.train.num_examples)
print("test examples:", mnist.test.num_examples)
print("validation examples:", mnist.validation.num_examples)

#print(mnist.train.images[0])

print(mnist.train.images.shape)
print(mnist.train.labels.shape)

print("num train examples:", mnist.train.num_examples)
print("num test examples:", mnist.test.num_examples)

print("Shape of training image data:", mnist.train.images.shape)
print("Shape of training label data:", mnist.train.labels.shape)


train examples: 55000
test examples: 10000
validation examples: 5000
(55000, 784)
(55000, 10)
num train examples: 55000
num test examples: 10000
Shape of training image data: (55000, 784)
Shape of training label data: (55000, 10)

In [5]:
data_sets = mnist # so we can cut/paste to and from our code

edge_labels = data_sets.train.labels.shape[1]
print(edge_labels)

print(data_sets.train.labels[0])


10
[ 0.  0.  0.  0.  0.  0.  0.  1.  0.  0.]

In [6]:
example_image_index = 4300
an_image = data_sets.train.images[example_image_index]
values = []
for y in range(28):
    print()
    for x in range(28):
        value = an_image[x + 28*y]
        values.append(value)
        if value > 0:
            print("1", end="")
        else:
            print("0", end="")
print("\nThe label array for this image is:", data_sets.train.labels[example_image_index])


0000000000000000000000000000
0000000000000000000000000000
0000000000000000000000000000
0000000000000000000000000000
0000001111111111110000000000
0000001111111111111000000000
0000001111100011111000000000
0000000000000001111000000000
0000000000000001111000000000
0000000000000011111000000000
0000000000001111111000000000
0000000000011111110000000000
0000000011111111100000000000
0000000011111111000000000000
0000000011111111111100000000
0000000001111111111110000000
0000000000000111111111000000
0000000000000001111111000000
0000000000000000001111000000
0000000000000000011111000000
0000000111111111111111000000
0000011111111111111111000000
0000011111111111111110000000
0000000011111111111000000000
0000000000000000000000000000
0000000000000000000000000000
0000000000000000000000000000
0000000000000000000000000000
The label array for this image is: [ 0.  0.  0.  1.  0.  0.  0.  0.  0.  0.]

In [1]:
import matplotlib.pyplot as plt
%matplotlib inline
plt.imshow(an_image)


---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-1-89834a0487e0> in <module>()
----> 1 import matplotlib.pyplot as plt
      2 get_ipython().magic('matplotlib inline')
      3 plt.imshow(an_image)

/Users/dansilberman/.virtualenvs/polygoggles/lib/python3.5/site-packages/matplotlib/pyplot.py in <module>()
    112 
    113 from matplotlib.backends import pylab_setup
--> 114 _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
    115 
    116 _IP_REGISTERED = None

/Users/dansilberman/.virtualenvs/polygoggles/lib/python3.5/site-packages/matplotlib/backends/__init__.py in pylab_setup()
     30     # imports. 0 means only perform absolute imports.
     31     backend_mod = __import__(backend_name,
---> 32                              globals(),locals(),[backend_name],0)
     33 
     34     # Things we pull in from all backends

/Users/dansilberman/.virtualenvs/polygoggles/lib/python3.5/site-packages/matplotlib/backends/backend_macosx.py in <module>()
     22 
     23 import matplotlib
---> 24 from matplotlib.backends import _macosx
     25 
     26 

RuntimeError: Python is not installed as a framework. The Mac OS X backend will not be able to function correctly if Python is not installed as a framework. See the Python documentation for more information on installing Python as a framework on Mac OS X. Please either reinstall Python as a framework, or try one of the other backends. If you are Working with Matplotlib in a virtual enviroment see 'Working with Matplotlib in Virtual environments' in the Matplotlib FAQ

In [7]:
print(values)


[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.18823531, 0.52549022, 0.99215692, 1.0, 0.99215692, 0.99215692, 0.99215692, 0.60000002, 0.37647063, 0.76078439, 0.37647063, 0.047058828, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.49803925, 0.98431379, 0.98431379, 0.99215692, 0.81176478, 0.24313727, 0.78823537, 0.47450984, 0.91372555, 0.98431379, 0.98431379, 0.6156863, 0.047058828, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.24705884, 0.49411768, 0.49411768, 0.49411768, 0.12156864, 0.0, 0.0, 0.0, 0.18823531, 0.86274517, 0.98431379, 0.98431379, 0.67843139, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.20000002, 0.98431379, 0.98431379, 0.98431379, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.51372552, 0.98431379, 0.98431379, 0.98431379, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.99215692, 0.99215692, 0.99215692, 0.75686282, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.031372551, 0.51372552, 0.99215692, 0.98431379, 0.98431379, 0.80000007, 0.090196081, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.25098041, 0.61960787, 0.98431379, 0.99215692, 0.98431379, 0.73725492, 0.36862746, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.15686275, 0.87450987, 0.86666673, 0.92549026, 0.98431379, 0.98431379, 0.99215692, 0.72156864, 0.058823533, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.61960787, 0.99215692, 0.98431379, 0.98431379, 0.98431379, 0.98431379, 0.99215692, 0.63137257, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3921569, 1.0, 0.99215692, 0.99215692, 0.99215692, 0.99215692, 1.0, 0.99215692, 0.99215692, 0.83529419, 0.37647063, 0.23529413, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4784314, 0.86274517, 0.86274517, 0.86274517, 0.94117653, 0.99215692, 0.98431379, 0.98431379, 0.98431379, 0.98431379, 0.66666669, 0.10980393, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.30980393, 0.49411768, 0.5529412, 0.98431379, 0.98431379, 0.98431379, 0.99215692, 0.92549026, 0.24705884, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.015686275, 0.12156864, 0.27450982, 0.89411771, 0.99215692, 0.98431379, 0.49411768, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.61960787, 0.99215692, 0.98431379, 0.49411768, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.32941177, 0.76078439, 1.0, 0.99215692, 0.49411768, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.10980393, 0.1254902, 0.1254902, 0.1254902, 0.1254902, 0.1254902, 0.1254902, 0.36078432, 0.74509805, 0.74509805, 0.95686281, 0.98431379, 0.99215692, 0.98431379, 0.49411768, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.062745102, 0.49803925, 0.92549026, 0.98431379, 0.99215692, 0.98431379, 0.98431379, 0.98431379, 0.98431379, 0.99215692, 0.98431379, 0.98431379, 0.98431379, 0.98431379, 0.99215692, 0.92156869, 0.24705884, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.015686275, 0.43137258, 0.73725492, 0.89411771, 0.99215692, 0.98431379, 0.98431379, 0.98431379, 0.98431379, 0.99215692, 0.98431379, 0.98431379, 0.98431379, 0.82745105, 0.50588238, 0.10588236, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.23137257, 0.37254903, 0.83137262, 0.98431379, 0.98431379, 0.98431379, 0.99215692, 0.98431379, 0.67450982, 0.36862746, 0.13725491, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]

In [8]:
sess = tf.InteractiveSession()

In [9]:
# Define the model
edge_labels = data_sets.train.labels.shape[1]

image_widths = 28
image_heights = 28
image_flat_size = image_widths * image_heights

print("Number of allowed num_edges (ie, size of output vector):", edge_labels)
print("Total image flat size (width * height):", image_flat_size)


Number of allowed num_edges (ie, size of output vector): 10
Total image flat size (width * height): 784

In [11]:
x = tf.placeholder(tf.float32, [None, image_flat_size])
print(x)
W = tf.Variable(tf.zeros([image_flat_size, edge_labels]))
print(W)
b = tf.Variable(tf.zeros([edge_labels]))
y = tf.nn.softmax(tf.matmul(x, W) + b)


Tensor("Placeholder_1:0", shape=(?, 784), dtype=float32)
<tensorflow.python.ops.variables.Variable object at 0x109579128>

In [15]:
# Define loss and optimizer
y_ = tf.placeholder(tf.float32, [None, edge_labels])
cross_entropy = -tf.reduce_sum(y_ * tf.log(y))
train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cross_entropy)

In [19]:
# Train
tf.initialize_all_variables().run()
for i in range(1000):
    batch_xs, batch_ys = mnist.train.next_batch(100)
    train_step.run({x: batch_xs, y_: batch_ys})

In [20]:
# Test trained model
correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(accuracy.eval({ x: data_sets.test.images, y_: data_sets.test.labels}))


0.912

In [ ]: