-
Notifications
You must be signed in to change notification settings - Fork 0
/
model_architecture.py
69 lines (61 loc) · 2.68 KB
/
model_architecture.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
# SPDX-FileCopyrightText: Copyright © Idiap Research Institute <[email protected]>
#
# SPDX-FileContributor: S. Pavankumar Dubagunta <[email protected]>
# SPDX-FileContributor: Mathew Magimai Doss <[email protected]>
# SPDX-FileContributor: Olivier Canévet <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-only
"""Define the model architecture for keras."""
import keras
def model_architecture(arch, inputFeatDim=4000, outputFeatDim=1):
"""Define the speech classification model."""
if arch == "subseg":
m = keras.models.Sequential(
[
keras.layers.Input((inputFeatDim,)),
keras.layers.Reshape((inputFeatDim, 1)),
keras.layers.Conv1D(filters=128, kernel_size=30, strides=10),
keras.layers.Activation("relu"),
keras.layers.MaxPooling1D(2),
keras.layers.Conv1D(filters=256, kernel_size=10, strides=5),
keras.layers.Activation("relu"),
keras.layers.MaxPooling1D(3),
keras.layers.Conv1D(filters=512, kernel_size=4, strides=2),
keras.layers.Activation("relu"),
keras.layers.Conv1D(filters=512, kernel_size=3, strides=1),
keras.layers.Activation("relu"),
# keras.layers.Flatten(),
keras.layers.GlobalAveragePooling1D(),
keras.layers.Dense(10),
keras.layers.Activation("relu"),
],
)
elif arch == "seg":
m = keras.models.Sequential(
[
keras.layers.Input((inputFeatDim,)),
keras.layers.Reshape((inputFeatDim, 1)),
keras.layers.Conv1D(filters=128, kernel_size=300, strides=100),
keras.layers.Activation("relu"),
keras.layers.MaxPooling1D(2),
keras.layers.Conv1D(filters=256, kernel_size=5, strides=2),
keras.layers.Activation("relu"),
keras.layers.Conv1D(filters=512, kernel_size=4, strides=2),
keras.layers.Activation("relu"),
keras.layers.Conv1D(filters=512, kernel_size=3, strides=1),
keras.layers.Activation("relu"),
# keras.layers.Flatten(),
keras.layers.GlobalAveragePooling1D(),
keras.layers.Dense(10),
keras.layers.Activation("relu"),
],
)
else:
raise TypeError(f"Unknown architecture: {arch}")
# Add the final layer
m.add(keras.layers.Dense(outputFeatDim))
if outputFeatDim == 1:
m.add(keras.layers.Activation("sigmoid"))
else:
m.add(keras.layers.Activation("softmax"))
return m