-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
46 lines (38 loc) · 1.16 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
43
44
45
import torch
import torch.nn as nn
class Generator(nn.Module):
def __init__(self, latent_dim):
super(Generator, self).__init__()
self.module_list = nn.Sequential(
*self.block(latent_dim, 256, bn=False),
*self.block(256, 512),
*self.block(512, 1024),
nn.Linear(1024, 28 * 28)
)
self.act = nn.Tanh()
def forward(self, x):
x = self.module_list(x)
x = x.view(-1, 1, 28, 28)
x = self.act(x)
return x
def block(self, in_channel, out_channel, bn=True):
layers = []
layers.append(nn.Linear(in_channel, out_channel))
if bn:
layers.append(nn.BatchNorm1d(out_channel))
layers.append(nn.LeakyReLU())
return layers
class Critic(nn.Module):
def __init__(self, ):
super(Critic, self).__init__()
self.model = nn.Sequential(
nn.Linear(28 * 28, 512),
nn.LeakyReLU(),
nn.Linear(512, 256),
nn.LeakyReLU(),
nn.Linear(256, 1),
)
def forward(self, x):
bs = x.shape[0]
x = x.view(bs, -1)
return self.model(x)