-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomTest.py
63 lines (55 loc) · 1.63 KB
/
customTest.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import layer
import customData
import numpy as np
import modelParser as mp
filepath = "./model.txt"
print("Running...\n\n")
parsed_file = mp.Parser(filepath, 4)
custom_test_images = []
custom_test_labels = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
imageNames = ["Nikhil_zero",
"Nikhil_one",
"Nikhil_two",
"Nikhil_three",
"Nikhil_four",
"Nikhil_five",
"Nikhil_six",
"Nikhil_seven",
"Nikhil_eight",
"Nikhil_nine"]
for name in imageNames:
imagePath = "./custom_data/" + name + ".jpg"
array = customData.extract_custom_data(imagePath)
custom_test_images.append(array)
"""
Initialize Neural layers.
"""
l1 = layer.Layer(784, 784, parsed_file.data[0])
l2 = layer.Layer(784, 10, parsed_file.data[1])
l3 = layer.Layer(10, 10, parsed_file.data[2])
"""
Loops 3 times over the entire dataset of 60000 pictures.
Prints the overall accuracy of our network after each iteration
"""
number_of_correct = 0
total_number = 0
for img, label in zip(custom_test_images, custom_test_labels):
"""
Forward propagation
"""
l1.forward(img)
l2.forward(l1.output)
l3.forward(l2.output)
rounded = []
for num in l3.output:
rounded.append(round(num, 2))
print(rounded)
print(label)
pred_max = np.argmax(l3.output)
if pred_max == label:
number_of_correct += 1
total_number += 1
print("FINAL ACCURACY OF ITERATION: " + str((number_of_correct / total_number) * 100) + "%")
print("CORRECT: " + str(number_of_correct))
print("INCORRECT: " + str(total_number - number_of_correct))
print("\n\nFinished...")