-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathalgorithm.py
58 lines (39 loc) · 958 Bytes
/
algorithm.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
def ReadImages:
for image in range(TrainingImages):
image = convertToPixels(image)
image = Zscore(image)
return image
filters1 = initWeights()
filters2 = initWeights()
weights_HL = initWeights()
weights_FC = initWeights()
bias1 = initBias()
bias2 = initBias()
biasFC = initBias()
biasHL = initBias()
def Zscore:
return (x-mean)/std_deviation
def main:
for epoch in range(epochs):
for image in range(TrainingImages):
# feed forward
input = ReadImages()
c = convolute(input)
n = normalize(c)
act_fn = sigmoid(n)
pool = pool(act_fn)
c = convolute(pool)
n = normalize(c)
act_fn = sigmoid(n)
pool = pool(act_fn)
FC = Flatten(pool)
hl = dot(weights_FC, FC)
output = dot(weights_HL, hl)
output = sigmoid(ouput)
# Back propagation
error = target - output
for each layer:
slope = derivative(x)
change_factor = error*slope
dw = dot(change_factor, values)
w = w - dw