/
DFAD_model_base.py
100 lines (64 loc) · 2.18 KB
/
DFAD_model_base.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import torch.nn as nn
class AuModel(nn.Module):
def __init__(self):
super(AuModel, self).__init__()
dropout_rate = 0.6
self.layers = nn.Sequential(
nn.Linear(768, 768),
nn.BatchNorm1d(768),
nn.ReLU(),
nn.Dropout(p=dropout_rate),
nn.Linear(768, 768),
nn.BatchNorm1d(768),
nn.ReLU(),
nn.Dropout(p=dropout_rate),
nn.Linear(768, 768),
nn.BatchNorm1d(768),
nn.ReLU(),
nn.Dropout(p=dropout_rate),
)
#
self.output_layer = nn.Linear(768, 12)
#he initialization
for layer in self.layers:
if isinstance(layer, nn.Linear):
nn.init.kaiming_uniform_(layer.weight, mode='fan_in', nonlinearity='relu')
nn.init.kaiming_uniform_(self.output_layer.weight, mode='fan_in', nonlinearity='relu')
def forward(self, x):
x = self.layers(x)
output = self.output_layer(x)
return output
#expr model
class DFADModel(nn.Module):
def __init__(self):
super(DFADModel, self).__init__()
dropout_rate = 0.6
leaky_relu_slope = 0.01
self.layers = nn.Sequential(
nn.Linear(768, 768),
nn.BatchNorm1d(768),
nn.ReLU(),
nn.Dropout(p=dropout_rate),
nn.Linear(768, 768),
nn.BatchNorm1d(768),
nn.ReLU(),
nn.Dropout(p=dropout_rate),
nn.Linear(768, 768),
nn.BatchNorm1d(768),
nn.ReLU(),
nn.Dropout(p=dropout_rate),
)
#
self.output_layer = nn.Linear(768, 8)
#he initialization
for layer in self.layers:
if isinstance(layer, nn.Linear):
nn.init.kaiming_uniform_(layer.weight, mode='fan_in', nonlinearity='relu')
nn.init.kaiming_uniform_(self.output_layer.weight, mode='fan_in', nonlinearity='relu')
def forward(self, x):
x = self.layers(x)
output = self.output_layer(x)
return output
if __name__ == '__main__':
model = DFADModel()
print(model)