forked from saturn-lab/audioNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
68 lines (57 loc) · 2.06 KB
/
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
#!/opt/anaconda3/bin/python
import tensorflow as tf
import numpy
from fourierWeight import fourierLayer, fourierLayerShape, fourierWeight
from keras.models import Model
from keras.regularizers import l2
from keras.optimizers import Adam
from keras.layers import (
Input,
Dense,
# Convolution2D,
Conv2D,
Lambda,
Activation,
Flatten,
Dropout,
Bidirectional,
LSTM,
Reshape,
TimeDistributed
)
DROP_RATE=0.5
L2_RATE=0.0001
def KerasModel(isCompile=True):
In = Input(shape=(None, 1, 1))
x = Lambda(fourierLayer, output_shape=fourierLayerShape)(In)
#x = Convolution2D(32, 7, 7, subsample=(3,3), activation='relu', W_regularizer=l2(L2_RATE))(x)
x = Conv2D(32, (7, 7), activation='relu', subsample=(3,3), W_regularizer=l2(L2_RATE))(x)
#x = Dropout(DROP_RATE)(x)
#x = Convolution2D(64, 7, 5, subsample=(3,3), activation='relu', W_regularizer=l2(L2_RATE))(x)
x = Conv2D(64, (7, 5), activation='relu', subsample=(3,3), W_regularizer=l2(L2_RATE))(x)
#x = Dropout(DROP_RATE)(x)
#x = Convolution2D(64, 3, 3, subsample=(2,2), activation='relu', W_regularizer=l2(L2_RATE))(x)
x = Conv2D(64, (3, 3), activation='relu', subsample=(2,2), W_regularizer=l2(L2_RATE))(x)
#x = Dropout(DROP_RATE)(x)
#x = Convolution2D(32, 3, 3, subsample=(2,2), activation='relu', W_regularizer=l2(L2_RATE))(x)
x = Conv2D(32, (3, 3), activation='relu', subsample=(2,2), W_regularizer=l2(L2_RATE))(x)
#x = Dropout(DROP_RATE)(x)
freq, chan = x.get_shape()[2:4]
x = TimeDistributed(Reshape([int(freq)*int(chan)]))(x)
x = Bidirectional(LSTM(128, ))(x)
#x = Dropout(DROP_RATE)(x)
x = Dense(64, activation='relu')(x)
#x = Dropout(DROP_RATE)(x)
x = Dense(24, activation='softmax')(x)
model = Model(inputs=In, outputs=x)
if isCompile:
opt = Adam(1e-4)
model.compile(
optimizer=opt,
loss='categorical_crossentropy',
metrics=['accuracy'],
)
return model
if __name__ == '__main__':
#model()
KerasModel()