-
Notifications
You must be signed in to change notification settings - Fork 46
/
models.py
72 lines (62 loc) · 1.38 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import torch
import torch.nn as nn
class Generator(nn.Module):
"""
the generator in a GAN
"""
def __init__(self,n_features=100):
super().__init__()
n_out = 784
self.hidden0 = nn.Sequential(
nn.Linear(n_features,256),
nn.LeakyReLU(0.2)
)
self.hidden1 = nn.Sequential(
nn.Linear(256,512),
nn.LeakyReLU(0.2)
)
self.hidden2 = nn.Sequential(
nn.Linear(512,1024),
nn.LeakyReLU(0.2)
)
self.out = nn.Sequential(
nn.Linear(1024,n_out),
nn.Tanh()
)
def forward(self,x):
x = self.hidden0(x)
x = self.hidden1(x)
x = self.hidden2(x)
x = self.out(x)
return x
class Discriminator(nn.Module):
def __init__(self):
super().__init__()
n_features = 784
n_out = 1
self.hidden0 = nn.Sequential(
nn.Linear(n_features,1024),
nn.LeakyReLU(0.2),
nn.Dropout(0.3)
)
self.hidden1 = nn.Sequential(
nn.Linear(1024,512),
nn.LeakyReLU(0.2),
nn.Dropout(0.3)
)
self.hidden2 = nn.Sequential(
nn.Linear(512,256),
nn.LeakyReLU(0.2),
nn.Dropout(0.3)
)
self.out = nn.Sequential(
nn.Linear(256,n_out),
nn.Sigmoid()
)
def forward(self, x):
x = x.view(-1,784)
x = self.hidden0(x)
x = self.hidden1(x)
x = self.hidden2(x)
x = self.out(x)
return x