-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmycounter.py
54 lines (39 loc) · 1.09 KB
/
mycounter.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
input = [[0, 0, 0], # 0
[0, 0, 1], # 1
[0, 1, 0], # 2
[0, 1, 1], # 3
[1, 0, 0], # 4
[1, 0, 1], # 5
[1, 1, 0], # 6
[1, 1, 1]] # 7
output = [[0, 0, 1], # 1
[0, 1, 0], # 2
[0, 1, 1], # 3
[1, 0, 0], # 4
[1, 0, 1], # 5
[1, 1, 0], # 6
[1, 1, 1], # 7
[0, 0, 0]] # 0
from keras.models import Sequential
from keras.layers import Dense
# make a model
model = Sequential()
# add a Dense layer with sigmoid activation
model.add(Dense(3, input_shape=(3,), activation='sigmoid'))
# specified loss and "minimization"
model.compile(loss='binary_crossentropy', optimizer='SGD')
model.summary()
# training
model.fit(input, output, epochs=10000, verbose=0)
# prediction
preds = model.predict(input)
def decoder(vect):
answer = []
for item in vect.tolist():
if item > 0.5:
answer.append(1)
else:
answer.append(0)
return answer
for idx in range(len(input)):
print("input:", input[idx], "true:", output[idx], "pred:", decoder(preds[idx]))