forked from Coobiw/Context-Encoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnetD.py
65 lines (61 loc) · 1.79 KB
/
netD.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
55
56
57
58
59
60
61
62
63
64
65
import numpy as np
import torch
from torch import nn
# from torch.utils.tensorboard import SummaryWriter
import cfg
class Net_D(nn.Module):
def __init__(self):
super(Net_D, self).__init__()
self.block1 = nn.Sequential(
nn.Conv2d(1, 64, 3, 1, 1),
nn.BatchNorm2d(64),
nn.LeakyReLU(0.2,inplace=True),
nn.MaxPool2d(2)
)
self.block2 = nn.Sequential(
nn.Conv2d(64, 64, 3, 1, 1),
nn.BatchNorm2d(64),
nn.LeakyReLU(0.2,inplace=True),
nn.MaxPool2d(2)
)
self.block3 = nn.Sequential(
nn.Conv2d(64, 128, 3, 1, 1),
nn.BatchNorm2d(128),
nn.LeakyReLU(0.2,inplace=True),
nn.MaxPool2d(2)
)
self.block4 = nn.Sequential(
nn.Conv2d(128, 256, 3, 1, 1),
nn.BatchNorm2d(256),
nn.LeakyReLU(0.2,inplace=True),
nn.MaxPool2d(2)
)
self.block5 = nn.Sequential(
nn.Conv2d(256, 512, 3, 1, 1),
nn.BatchNorm2d(512),
nn.LeakyReLU(0.2,inplace=True),
nn.MaxPool2d(2)
)
self.block6 = nn.Sequential(
nn.Conv2d(512, 1, 4, 1, 0)
)
self.sigmoid = nn.Sigmoid()
def forward(self,x):
x = self.block1(x)
x = self.block2(x)
x = self.block3(x)
x = self.block4(x)
x = self.block5(x)
x = self.block6(x)
x = x.view(-1,1)
out = self.sigmoid(x)
return out
if __name__ == '__main__':
x = torch.rand(4, 1, 128, 128)
print("input_size:", x.size())
net = Net_D()
y = net(x)
print(y)
print("output_size:", y.size())
# with SummaryWriter(log_dir='netD_structure',comment='Net_FCN') as w:
# w.add_graph(net,(x,))