-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
executable file
·54 lines (44 loc) · 1.33 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
46
47
48
49
50
51
52
53
54
import torch.nn as nn
import torch.nn.functional as F
class Generator(nn.Module):
def __init__(self):
super(Generator, self).__init__()
self.main = nn.Sequential(
nn.Linear(100, 100),
nn.BatchNorm1d(100),
nn.ReLU(True),
nn.Linear(100, 100),
nn.BatchNorm1d(100),
nn.ReLU(True),
nn.Linear(100, 100),
nn.BatchNorm1d(100),
nn.ReLU(True),
nn.Linear(100, 100)
)
def forward(self, input):
output = self.main(input)
return output
class Discriminator(nn.Module):
def __init__(self):
super(Discriminator, self).__init__()
self.main1 = nn.Sequential(
nn.Linear(100, 100),
nn.BatchNorm1d(100),
nn.LeakyReLU(inplace=True),
nn.Linear(100, 100)
)
self.main2 = nn.Sequential(
nn.BatchNorm1d(100),
nn.LeakyReLU(inplace=True),
nn.Linear(100, 32),
nn.BatchNorm1d(32),
nn.LeakyReLU(inplace=True),
nn.Linear(32, 1),
nn.Sigmoid()
)
def forward(self, input, intermediate=False):
inter = self.main1(input)
if intermediate:
return inter
output = self.main2(inter)
return output