SNABSuite  0.x
Spiking Neural Architecture Benchmark Suite
mnist_view.py
Go to the documentation of this file.
1 from __future__ import print_function
2 
3 from keras.datasets import mnist
4 import matplotlib
5 matplotlib.use('TkAgg')
6 import matplotlib.pyplot as plt
7 # the data, split between train and test sets
8 (x_train, y_train), (x_test, y_test) = mnist.load_data()
9 
10 x_train = x_train.reshape(60000, 784)
11 x_test = x_test.reshape(10000, 784)
12 x_train = x_train.astype('float32')
13 x_test = x_test.astype('float32')
14 x_train /= 255
15 x_test /= 255
16 nr_images = 5
17 #for i in range(0,10):
18  #print(x_train[i])
19  #print(y_train[i])
20  #plt.imshow(x_train[i].reshape((28,28)), cmap='gray')
21  #plt.show()
22 
23 
24 for i in range(0,nr_images):
25  print(y_train[i], ", ")
26 
27 with open("train.txt", 'w') as file:
28  file.write("{")
29  for i in range(0,nr_images):
30  file.write(str(y_train[i]))
31  file.write(", ")
32  file.write("}\n")
33 
34  file.write("{")
35  for i in range(0,nr_images):
36  file.write("{")
37  for j in range(0,len(x_train[i])):
38  file.write(str(x_train[i][j]))
39  file.write(", ")
40  file.write("}, \n")
41  file.write("}\n")
42 
43 with open("test.txt", 'w') as file:
44  file.write("{")
45  for i in range(0,nr_images):
46  file.write(str(y_test[i]))
47  file.write(", ")
48  file.write("}\n")
49 
50  file.write("{")
51  for i in range(0,nr_images):
52  file.write("{")
53  for j in range(0,len(x_test[i])):
54  file.write(str(x_test[i][j]))
55  file.write(", ")
56  file.write("}, \n")
57 
58  file.write("}")