-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmodel.py
42 lines (38 loc) · 1.78 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
import numpy as np
from torch import nn
class Autoencoder(nn.Module):
def __init__(self, input_dim):
super(Autoencoder, self).__init__()
# self.encoder = nn.Sequential(
# nn.Linear(input_dim, encoding_dim),
# nn.Tanh(),
# nn.Linear(encoding_dim, encoding_dim // 2),
# nn.ReLU()
# )
# self.decoder = nn.Sequential(
# nn.Linear(encoding_dim // 2, encoding_dim),
# nn.Tanh(),
# nn.Linear(encoding_dim, input_dim),
# nn.ReLU()
# )
# The Kitsune AE model
self.encoder = nn.Sequential(nn.Linear(input_dim, int(input_dim*0.75)),
nn.ReLU(True),
nn.Linear(int(input_dim*0.75), int(input_dim*0.5)),
nn.ReLU(True),
nn.Linear(int(input_dim*0.5),int(input_dim*0.25)),
nn.ReLU(True),
# nn.Dropout(0.2), # add dropout after relu
nn.Linear(int(input_dim*0.25),int(input_dim*0.1)))
self.decoder = nn.Sequential(nn.Linear(int(input_dim*0.1),int(input_dim*0.25)),
nn.ReLU(True),
nn.Linear(int(input_dim*0.25),int(input_dim*0.5)),
nn.ReLU(True),
nn.Linear(int(input_dim*0.5),int(input_dim*0.75)),
nn.ReLU(True),
nn.Linear(int(input_dim*0.75),int(input_dim)),
)
def forward(self, x):
x = self.encoder(x)
x = self.decoder(x)
return x