-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
39 lines (33 loc) · 1.12 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
import torch
from torch.nn import Module, Linear
import torch.nn.functional as F
class Generator(Module):
def __init__(self):
super(Generator, self).__init__()
self.fc1 = Linear(100, 256)
self.fc2 = Linear(256, 512)
self.fc3 = Linear(512, 1024)
self.fc4 = Linear(1024, 28 * 28)
def forward(self, x):
x = F.leaky_relu(self.fc1(x), 0.2)
x = F.dropout(x, 0.3)
x = F.leaky_relu(self.fc2(x), 0.2)
x = F.dropout(x, 0.3)
x = F.leaky_relu(self.fc3(x), 0.2)
x = F.dropout(x, 0.3)
return torch.tanh(self.fc4(x))
class Discriminator(Module):
def __init__(self):
super(Discriminator, self).__init__()
self.fc1 = Linear(28*28, 1024)
self.fc2 = Linear(1024, 512)
self.fc3 = Linear(512, 256)
self.fc4 = Linear(256, 1)
def forward(self, x):
x = F.leaky_relu(self.fc1(x), 0.2)
x = F.dropout(x, 0.3)
x = F.leaky_relu(self.fc2(x), 0.2)
x = F.dropout(x, 0.3)
x = F.leaky_relu(self.fc3(x), 0.2)
x = F.dropout(x, 0.3)
return torch.sigmoid(self.fc4(x))