-
Notifications
You must be signed in to change notification settings - Fork 4
/
model.py
121 lines (94 loc) · 4.54 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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import torch.nn as nn
import torch.nn.functional as F
from torchvision import models
class Net(nn.Module):
def __init__(self):
super(Net, self).__init__()
self.down_conv1 = nn.Sequential(
nn.Conv2d(in_channels=1, out_channels=48, kernel_size=5, stride=2, padding=2),
nn.BatchNorm2d(num_features=48),
nn.ReLU(),
nn.Conv2d(in_channels=48, out_channels=128, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(num_features=128),
nn.ReLU(),
nn.Conv2d(in_channels=128, out_channels=128, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(num_features=128),
nn.ReLU(),
)
self.down_conv2 = nn.Sequential(
nn.Conv2d(in_channels=128, out_channels=256, kernel_size=3, stride=2, padding=1),
nn.BatchNorm2d(num_features=256),
nn.ReLU(),
nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(num_features=256),
nn.ReLU(),
nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(num_features=256),
nn.ReLU()
)
self.flat_conv = nn.Sequential(
nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=2, padding=1),
nn.BatchNorm2d(num_features=256),
nn.ReLU(),
nn.Conv2d(in_channels=256, out_channels=512, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(num_features=512),
nn.ReLU(),
nn.Conv2d(in_channels=512, out_channels=1024, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(num_features=1024),
nn.ReLU(),
nn.Conv2d(in_channels=1024, out_channels=1024, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(num_features=1024),
nn.ReLU(),
nn.Conv2d(in_channels=1024, out_channels=1024, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(num_features=1024),
nn.ReLU(),
nn.Conv2d(in_channels=1024, out_channels=1024, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(num_features=1024),
nn.ReLU(),
nn.Conv2d(in_channels=1024, out_channels=512, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(num_features=512),
nn.ReLU(),
nn.Conv2d(in_channels=512, out_channels=256, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(num_features=256),
nn.ReLU()
)
self.up_conv1 = nn.Sequential(
nn.ConvTranspose2d(in_channels=256, out_channels=256, kernel_size=4, stride=2, padding=1),
nn.BatchNorm2d(num_features=256),
nn.ReLU(),
nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(num_features=256),
nn.ReLU(),
nn.Conv2d(in_channels=256, out_channels=128, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(num_features=128),
nn.ReLU(),
)
self.up_conv2 = nn.Sequential(
nn.ConvTranspose2d(in_channels=128, out_channels=128, kernel_size=4, stride=2, padding=1),
nn.BatchNorm2d(num_features=128),
nn.ReLU(),
nn.Conv2d(in_channels=128, out_channels=128, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(num_features=128),
nn.ReLU(),
nn.Conv2d(in_channels=128, out_channels=48, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(num_features=48),
nn.ReLU(),
)
self.up_conv3 = nn.Sequential(
nn.ConvTranspose2d(in_channels=48, out_channels=48, kernel_size=4, stride=2, padding=1),
nn.BatchNorm2d(num_features=48),
nn.ReLU(),
nn.Conv2d(in_channels=48, out_channels=24, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(num_features=24),
nn.ReLU(),
nn.Conv2d(in_channels=24, out_channels=1, kernel_size=3, stride=1, padding=1),
nn.Sigmoid()
)
def forward(self, x):
x = self.down_conv1(x)
x = self.down_conv2(x)
x = self.flat_conv(x)
x = self.up_conv1(x)
x = self.up_conv2(x)
out = self.up_conv3(x)
return out