-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgan_disc.py
More file actions
43 lines (28 loc) · 1.46 KB
/
gan_disc.py
File metadata and controls
43 lines (28 loc) · 1.46 KB
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
# -*- coding: utf-8 -*-
"""GAN disc.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/15CXWy3aN0qKCyoEIhssxo1jiTRLcXnwL
"""
class Disc(nn.Module):
def __init__(self, img_feat = 3, n_feats = 64, kernel_size = 3, act = nn.LeakyReLU(inplace = True), num_of_block = 2, patch_size = 86):
super(Disc, self).__init__()
self.act = act
self.conv01 = conv(in_channel = img_feat, out_channel = n_feats, kernel_size = 3, BN = False, act = self.act)
self.conv02 = conv(in_channel = n_feats, out_channel = n_feats, kernel_size = 3, BN = False, act = self.act, stride = 2)
body = [discrim_block(in_feats = n_feats * (2 ** i), out_feats = n_feats * (2 ** (i + 1)), kernel_size = 3, act = self.act) for i in range(num_of_block)]
self.body = nn.Sequential(*body)
self.linear_size = ((patch_size // (2 ** (num_of_block + 1))) ** 2) * (n_feats * (2 ** num_of_block))
tail = []
tail.append(nn.Linear(self.linear_size, 1024))
tail.append(self.act)
tail.append(nn.Linear(1024, 1))
tail.append(nn.Sigmoid())
self.tail = nn.Sequential(*tail)
def forward(self, x):
x = self.conv01(x)
x = self.conv02(x)
x = self.body(x)
x = x.view(-1, self.linear_size)
x = self.tail(x)
return x