forked from pclubiitk/model-zoo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
55 lines (50 loc) · 1.41 KB
/
models.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
import torch.nn as nn
import torch
import torch.nn.functional as F
# We will use a normal deterministic encoder, which is same as the one used in an ordinary autoencoder
class encoder(nn.Module):
def __init__(self):
super().__init__()
self.block=nn.Sequential(
nn.Linear(784,1000),
nn.Dropout(p=.25),
nn.ReLU(True),
nn.Linear(1000,1000),
nn.Dropout(p=.25),
nn.ReLU(True),
nn.Linear(1000,8),
)
def forward(self,x):
bsize=x.size(0)
x=x.view(bsize,-1)
return self.block(x)
class decoder(nn.Module):
def __init__(self):
super().__init__()
self.block=nn.Sequential(
nn.Linear(8,1000),
nn.Dropout(p=.25),
nn.ReLU(True),
nn.Linear(1000,1000),
nn.Dropout(p=.25),
nn.ReLU(True),
nn.Linear(1000,784),
)
def forward(self,x):
x=self.block(x)
return F.sigmoid(x)
class discriminator(nn.Module):
def __init__(self):
super().__init__()
self.block=nn.Sequential(
nn.Linear(8,1000),
nn.Dropout(p=.2),
nn.ReLU(True),
nn.Linear(1000,1000),
nn.Dropout(p=.2),
nn.ReLU(True),
nn.Linear(1000,1)
)
def forward(self,x):
x=self.block(x)
return F.sigmoid(x)