-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.py
71 lines (50 loc) · 1.75 KB
/
Main.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
64
65
66
67
68
69
70
71
import GetInput
import Network
import numpy as np
import random
def GetAccuracy(set, network):
correctCount = 0
for image in set:
input = np.array(image[0])
expected = np.array(image[1])
output = net.Feedforwad(input)
if np.argmax(expected) == np.argmax(output):
correctCount += 1
return correctCount / len(set)
data = GetInput.LoadAllCategories("D:/Chris/Documents/School/Machine Learning/Project/4Categories", True)
# data = GetInput.LoadAllCategories("D:/Chris/Documents/School/Machine Learning/Project/SmallSet", True)
random.shuffle(data)
firstValidIndex = int(len(data) * .7)
firstTestIndex = int(len(data) * .85)
trainingSet = data[:firstValidIndex]
validationSet = data[firstValidIndex:firstTestIndex]
testingSet = data[firstTestIndex:]
net = Network.Network(len(data[0][0]), len(data[0][1]), [200])
groupCount = 0
groupSize = 250
count = 0
correct = 0
maxAcc = 0
for i in range(100):
for image in trainingSet:
input = np.array(image[0])
expected = np.array(image[1])
output = net.Feedforwad(input)
error = net.GetError(expected)
net.Backprop(expected, .01)
category = np.argmax(expected)
classify = np.argmax(output)
if category == classify:
correct += 1
count += 1
if count == groupSize:
print(groupCount, end= "\t")
print(correct / count, end='\t')
validAccuracy = GetAccuracy(validationSet, net)
print(validAccuracy)
if validAccuracy > maxAcc:
maxAcc = validAccuracy
groupCount += 1
correct = 0
count = 0
print(maxAcc)