-
Notifications
You must be signed in to change notification settings - Fork 22
/
architectures.py
76 lines (59 loc) · 2.5 KB
/
architectures.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
76
from keras.layers import Dense, Input, Dropout, Conv2D, BatchNormalization, MaxPooling2D, Flatten, Activation
from keras.models import Model
from keras.regularizers import l2
# =====================================================================================
def get_model_baseline(params_learn=None, params_extract=None):
"""
:param params_learn:
:param params_extract:
:return:
"""
input_shape = (1, params_extract.get('patch_len'), params_extract.get('n_mels'))
channel_axis = 1
n_class = params_learn.get('n_classes')
spec_start = Input(shape=input_shape)
spec_x = spec_start
# l1
spec_x = BatchNormalization(axis=1)(spec_x)
spec_x = Activation('relu')(spec_x)
spec_x = Conv2D(24, (5, 5),
padding='same', # fmap has same size as input
kernel_initializer='he_normal',
data_format='channels_first')(spec_x)
spec_x = BatchNormalization(axis=1)(spec_x)
spec_x = Activation('relu')(spec_x)
spec_x = MaxPooling2D(pool_size=(4, 2), data_format="channels_first")(spec_x)
# l2
spec_x = BatchNormalization(axis=1)(spec_x)
spec_x = Activation('relu')(spec_x)
spec_x = Conv2D(48, (5, 5),
padding='same', # fmap has same size as input
kernel_initializer='he_normal',
data_format='channels_first')(spec_x)
spec_x = BatchNormalization(axis=1)(spec_x)
spec_x = Activation('relu')(spec_x)
spec_x = MaxPooling2D(pool_size=(4, 2), data_format="channels_first")(spec_x)
# l3
spec_x = BatchNormalization(axis=1)(spec_x)
spec_x = Activation('relu')(spec_x)
spec_x = Conv2D(48, (5, 5),
padding='same', # fmap has same size as input
kernel_initializer='he_normal',
data_format='channels_first')(spec_x)
spec_x = BatchNormalization(axis=1)(spec_x)
spec_x = Activation('relu')(spec_x)
spec_x = Flatten()(spec_x)
spec_x = Dropout(0.5)(spec_x)
spec_x = Dense(64,
kernel_initializer='he_normal',
kernel_regularizer=l2(1e-3),
activation='relu',
name='dense_1')(spec_x)
spec_x = Dropout(0.5)(spec_x)
out = Dense(n_class,
kernel_initializer='he_normal',
kernel_regularizer=l2(1e-3),
activation='softmax',
name='prediction')(spec_x)
model = Model(inputs=spec_start, outputs=out)
return model