-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnet.py
49 lines (41 loc) · 1.89 KB
/
net.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
import torch.nn as nn
from torch.nn import functional as F
class Net(nn.Module):
def __init__(self, input_nc=3, discriminator_channel_base=64, norm=nn.BatchNorm2d):
super(Net, self).__init__()
model = [nn.Conv2d(in_channels=input_nc,
out_channels=discriminator_channel_base,
kernel_size=4,
stride=2,
padding=1),
nn.LeakyReLU(0.2,inplace=True)]
model += [nn.Conv2d(in_channels=discriminator_channel_base,
out_channels=discriminator_channel_base*2,
kernel_size=4,
stride=2,
padding=1),
norm(discriminator_channel_base*2),
nn.LeakyReLU(0.2,inplace=True)]
model += [nn.Conv2d(in_channels=discriminator_channel_base*2,
out_channels=discriminator_channel_base*4,
kernel_size=4,
stride=2,
padding=1),
norm(discriminator_channel_base*4),
nn.LeakyReLU(0.2,inplace=True)]
model += [nn.Conv2d(in_channels=discriminator_channel_base*4,
out_channels=discriminator_channel_base*8,
kernel_size=4,
padding=1),
norm(discriminator_channel_base*8),
nn.LeakyReLU(0.2,inplace=True) ]
model += [nn.Conv2d(in_channels=discriminator_channel_base*8,
out_channels=2,
kernel_size=4,
padding=1)]
self.model = nn.Sequential(*model)
def forward(self, x):
x = self.model(x)
x = F.avg_pool2d(x, x.size()[2:])
x = x.view(x.size(0),-1)
return x