-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
43 lines (36 loc) · 1.07 KB
/
test.py
File metadata and controls
43 lines (36 loc) · 1.07 KB
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
import layer
import data
import numpy as np
import modelParser as mp
filepath = "./model.txt"
print("Running...\n\n")
test_images, test_labels = data.get_test_data()
parsed_file = mp.Parser(filepath, 3)
"""
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(test_images, test_labels):
"""
Forward propagation
"""
l1.forward(img)
l2.forward(l1.output)
l3.forward(l2.output)
pred_max = np.argmax(l3.output)
target_max = np.argmax(label)
if pred_max == target_max:
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...")