-
Notifications
You must be signed in to change notification settings - Fork 0
/
ann_HCI.py
49 lines (39 loc) · 1.18 KB
/
ann_HCI.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
#!/usr/bin/python
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation
from keras.layers.advanced_activations import PReLU
from keras.optimizers import RMSprop
import numpy as np
from six.moves import cPickle
def build_pmodel():
model = Sequential()
model.add(Dense(10, input_dim = 2, activation='tanh'))
model.add(Dense(5, activation='tanh'))
model.add(Dense(1, activation='sigmoid'))
rms = RMSprop()
model.compile(loss='mse', optimizer='sgd')
return model
def build_fmodel():
model = Sequential()
model.add(Dense(10, input_dim = 6, activation='tanh'))
model.add(Dense(5, activation='tanh'))
model.add(Dense(1, activation='tanh'))
rms = RMSprop()
model.compile(loss='mse', optimizer='sgd')
return model
"""
m = build_model()
s = (2,3,4,5)
y = np.zeros((1,5))
m.fit(np.asarray(s).reshape(1,4), y, batch_size=1, nb_epoch=100, verbose=0)
a = m.predict(np.asarray(s).reshape(1,4), batch_size = 1)[0]
print a
f = open('obj.save', 'wb')
cPickle.dump(m, f, protocol=cPickle.HIGHEST_PROTOCOL)
f.close()
f = open('obj.save', 'rb')
loaded_obj = cPickle.load(f)
f.close()
a = loaded_obj.predict(np.asarray(s).reshape(1,4), batch_size = 1)[0]
print a
"""