-
Notifications
You must be signed in to change notification settings - Fork 10
/
keras_model.py
75 lines (55 loc) · 1.9 KB
/
keras_model.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
72
73
74
75
########################################################################
# import python-library
########################################################################
# from import
import keras.models
from keras import backend as K
from keras.layers import Input, Dense, BatchNormalization, Activation
from keras.models import Model
########################################################################
# keras model
########################################################################
def get_model(input_dim, lr):
"""
define the keras model
the model based on the simple dense auto encoder
(128*128*128*128*8*128*128*128*128)
"""
x = Input(shape=(input_dim,))
h = Dense(128)(x)
h = BatchNormalization()(h)
h = Activation('relu')(h)
h = Dense(128)(h)
h = BatchNormalization()(h)
h = Activation('relu')(h)
h = Dense(128)(h)
h = BatchNormalization()(h)
h = Activation('relu')(h)
h = Dense(128)(h)
h = BatchNormalization()(h)
h = Activation('relu')(h)
h = Dense(8)(h)
h = BatchNormalization()(h)
h = Activation('relu')(h)
h = Dense(128)(h)
h = BatchNormalization()(h)
h = Activation('relu')(h)
h = Dense(128)(h)
h = BatchNormalization()(h)
h = Activation('relu')(h)
h = Dense(128)(h)
h = BatchNormalization()(h)
h = Activation('relu')(h)
h = Dense(128)(h)
h = BatchNormalization()(h)
h = Activation('relu')(h)
h = Dense(input_dim)(h)
model = Model(inputs=x, outputs=h)
model.compile(optimizer=keras.optimizers.Adam(lr=lr),
loss='mean_squared_error')
return model
#########################################################################
def load_model(file_path):
return keras.models.load_model(file_path, compile=False)
def clear_session():
K.clear_session()