-
Notifications
You must be signed in to change notification settings - Fork 2
/
gru_fcn.py
77 lines (52 loc) · 1.96 KB
/
gru_fcn.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
77
# Implementation of GRU + FCN block
# Author: Shobhit Lamba
# e-mail: slamba4@uic.edu
# Importing the libraries
from keras.models import Model
from keras.layers import Input, Dense, GRU, concatenate, Activation
from keras.layers import Conv1D, BatchNormalization, GlobalAveragePooling1D, Permute, Dropout
from utils.se_block import squeeze_excite_block
MAX_SEQUENCE_LENGTH = 100 #Placeholder
NB_CLASSES = 100 # Placeholder
def gru_fcn_block():
ip = Input(shape = (1, MAX_SEQUENCE_LENGTH))
x = GRU()(ip)
x = Dropout(0.8)(x)
y = Permute((2, 1))(ip)
y = Conv1D(128, 8, padding = "same", kernel_initializer = "he_uniform")(y)
y = BatchNormalization()(y)
y = Activation("relu")(y)
y = Conv1D(256, 5, padding = "same", kernel_initializer = "he_uniform")(y)
y = BatchNormalization()(y)
y = Activation("relu")(y)
y = Conv1D(128, 3, padding = "same", kernel_initializer = "he_uniform")(y)
y = BatchNormalization()(y)
y = Activation("relu")(y)
y = GlobalAveragePooling1D()(y)
x = concatenate([x, y])
out = Dense(NB_CLASSES, activation = "softmax")(x)
model = Model(ip, out)
model.summary()
return model
def se_gru_fcn_block():
ip = Input(shape = (1, MAX_SEQUENCE_LENGTH))
x = GRU(8)(ip)
x = Dropout(0.8)(x)
y = Permute((2, 1))(ip)
y = Conv1D(128, 8, padding = "same", kernel_initializer = "he_uniform")(y)
y = BatchNormalization()(y)
y = Activation("relu")(y)
y = squeeze_excite_block(y)
y = Conv1D(256, 5, padding = "same", kernel_initializer = "he_uniform")(y)
y = BatchNormalization()(y)
y = Activation("relu")(y)
y = squeeze_excite_block(y)
y = Conv1D(128, 3, padding = "same", kernel_initializer = "he_uniform")(y)
y = BatchNormalization()(y)
y = Activation("relu")(y)
y = GlobalAveragePooling1D()(y)
x = concatenate([x, y])
out = Dense(NB_CLASSES, activation = "softmax")(x)
model = Model(ip, out)
model.summary()
return model