-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathf.py
43 lines (34 loc) · 1.33 KB
/
f.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# python notebook for Make Your Own Neural Network
# code for a 3-layer neural network, and code for learning the MNIST dataset
# (c) Tariq Rashid, 2016
# license is GPLv2
# helper to load data from PNG image files
import imageio
# glob helps select multiple files using patterns
import glob
import numpy
# library for plotting arrays
import matplotlib.pyplot
# ensure the plots are inside this notebook, not an external window
# our own image test data set
our_own_dataset = []
for image_file_name in glob.glob('778.png'):
print ("loading ... ", image_file_name)
# use the filename to set the correct label
label = int(image_file_name[-5:-4])
# load image data from png files into an array
img_array = imageio.imread(image_file_name, as_gray=True)
# reshape from 28x28 to list of 784 values, invert values
img_data = 255.0 - img_array.reshape(784)
# then scale data to range from 0.01 to 1.0
img_data = (img_data / 255.0 * 0.99) + 0.01
print(numpy.min(img_data))
print(numpy.max(img_data))
# append label and image data to test data set
record = numpy.append(label,img_data)
print(record)
our_own_dataset.append(record)
pass
matplotlib.pyplot.imshow(our_own_dataset[0][1:].reshape(28,28), cmap='Greys', interpolation='None')
matplotlib.pyplot.savefig("002.png")
print(our_own_dataset[0])