-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
35 lines (27 loc) · 840 Bytes
/
model.py
File metadata and controls
35 lines (27 loc) · 840 Bytes
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
import torch
from torch import nn
import torch.nn.functional as F
class autoencoderMLP4Layer(nn.Module):
def __init__(self, N_input=784, N_bottleneck=8, N_output=784):
super(autoencoderMLP4Layer, self).__init__()
N2 = 392
self.fc1 = nn.Linear(N_input, N2)
self.fc2 = nn.Linear(N2, N_bottleneck)
self.fc3 = nn.Linear(N_bottleneck, N2)
self.fc4 = nn.Linear(N2, N_output)
self.type = 'MLP4'
self.input_shape = (1, 28 * 28)
def encode(self, X):
X = self.fc1(X)
X = F.relu(X)
X = self.fc2(X)
X = F.relu(X)
return X
def decode(self, X):
X = self.fc3(X)
X = F.relu(X)
X = self.fc4(X)
X = torch.sigmoid(X)
return X
def forward(self, X):
return self.decode(self.encode(X))