forked from yubin1219/Deraindrop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiscriminator.py
79 lines (74 loc) · 1.93 KB
/
Discriminator.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import torch
import torch.nn as nn
class Discriminator(nn.Module):
def __init__(self):
super(Discriminator, self).__init__()
self.conv1 = nn.Sequential(
nn.Conv2d(3, 64, 5, 1, 2),
nn.LeakyReLU(0.2)
)
self.res1 = nn.Sequential(
nn.Conv2d(64, 32, 1, 1, 0),
nn.LeakyReLU(0.2),
nn.Conv2d(32, 32, 3, 1, 1),
nn.LeakyReLU(0.2),
nn.Conv2d(32, 64, 1, 1, 0)
)
self.res2 = nn.Sequential(
nn.Conv2d(64, 32, 1, 1, 0),
nn.LeakyReLU(0.2),
nn.Conv2d(32, 32, 3, 1, 1),
nn.LeakyReLU(0.2),
nn.Conv2d(32, 64, 1, 1, 0)
)
self.res3 = nn.Sequential(
nn.Conv2d(64, 32, 1, 1, 0),
nn.LeakyReLU(0.2),
nn.Conv2d(32, 32, 3, 1, 1),
nn.LeakyReLU(0.2),
nn.Conv2d(32, 64, 1, 1, 0)
)
self.res4 = nn.Sequential(
nn.Conv2d(64, 32, 1, 1, 0),
nn.LeakyReLU(0.2),
nn.Conv2d(32, 32, 3, 1, 1),
nn.LeakyReLU(0.2),
nn.Conv2d(32, 64, 1, 1, 0)
)
self.lrelu = nn.Sequential(
nn.LeakyReLU(0.2)
)
self.conv2 = nn.Sequential(
nn.Conv2d(64, 128, 3, 1, 1),
nn.LeakyReLU(0.2)
)
self.conv_mask = nn.Sequential(
nn.Conv2d(128, 1, 3, 1, 1)
)
self.conv3 = nn.Sequential(
nn.Conv2d(128, 64, 5, 4, 1),
nn.LeakyReLU(0.2)
)
self.conv4 = nn.Sequential(
nn.Conv2d(64, 32, 5, 4, 1),
nn.LeakyReLU(0.2)
)
self.fc = nn.Sequential(
nn.Linear(32 * 22 * 15, 1024),
nn.Linear(1024, 1),
nn.Sigmoid()
)
def forward(self, x):
x = self.conv1(x)
x = self.res1(x) + x
x = self.res2(x) + x
x = self.res3(x) + x
x = self.res4(x) + x
x = self.lrelu(x)
x = self.conv2(x)
mask = self.conv_mask(x)
x = x * mask
x = self.conv3(x)
x = self.conv4(x)
x = x.reshape(x.size(0), -1)
return [mask, self.fc(x)]