-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
48 lines (38 loc) · 1.39 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
import torch.nn as nn
import torch.nn.functional as F
# G(z)
class generator(nn.Module):
# initializers
def __init__(self, input_size=32, image_size=28*28):
super(generator, self).__init__()
self.fc1 = nn.Linear(input_size, 256)
self.fc2 = nn.Linear(self.fc1.out_features, 512)
self.fc3 = nn.Linear(self.fc2.out_features, 1024)
self.fc4 = nn.Linear(self.fc3.out_features, image_size)
# forward method
def forward(self, input):
x = F.leaky_relu(self.fc1(input), 0.2)
x = F.leaky_relu(self.fc2(x), 0.2)
x = F.leaky_relu(self.fc3(x), 0.2)
x = F.tanh(self.fc4(x))
return x
class discriminator(nn.Module):
# initializers
def __init__(self, input_size=32, lable_size=1):
super(discriminator, self).__init__()
self.fc1 = nn.Linear(input_size, 1024)
self.fc2 = nn.Linear(self.fc1.out_features, 512)
self.fc3 = nn.Linear(self.fc2.out_features, 256)
self.fc4 = nn.Linear(self.fc3.out_features, lable_size)
# forward method
def forward(self, input):
x = F.leaky_relu(self.fc1(input), 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)
x = F.sigmoid(self.fc4(x))
return x
# Binary Cross Entropy loss
BCE_loss = nn.BCELoss()