-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGenericBlocks.py
78 lines (60 loc) · 2.16 KB
/
GenericBlocks.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
import torch.nn as nn
class DoubleConv(nn.Module):
def __init__(self, c_in, c_out):
super(DoubleConv, self).__init__()
self.conv = nn.Sequential(
nn.Conv2d(in_channels=c_in, out_channels=c_out, kernel_size=3),
nn.ReLU(inplace=True),
nn.Conv2d(in_channels=c_out, out_channels=c_out, kernel_size=3),
nn.ReLU(inplace=True),
)
def forward(self, x):
return self.conv(x)
class DoubleConvSame(nn.Module):
def __init__(self, c_in, c_out):
super(DoubleConvSame, self).__init__()
self.conv = nn.Sequential(
nn.Conv2d(in_channels=c_in, out_channels=c_out, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
nn.Conv2d(in_channels=c_out, out_channels=c_out, kernel_size=3, padding=1),
nn.ReLU(inplace=True),
)
def forward(self, x):
return self.conv(x)
class DoubleConvSame3D(nn.Module):
def __init__(self, c_in, c_out):
super(DoubleConvSame3D, self).__init__()
self.conv = nn.Sequential(
nn.Conv3d(
in_channels=c_in, out_channels=c_out, kernel_size=3, stride=1, padding=1
),
nn.ReLU(inplace=True),
nn.Conv3d(
in_channels=c_out,
out_channels=c_out,
kernel_size=3,
stride=1,
padding=1,
),
nn.ReLU(inplace=True),
)
def forward(self, x):
return self.conv(x)
class Encoder(nn.Module):
def __init__(self, in_channels):
super(Encoder, self).__init__()
self.conv = DoubleConvSame(c_in=in_channels, c_out=in_channels * 2)
self.pool = nn.MaxPool2d(kernel_size=2, stride=2)
def forward(self, x):
c = self.conv(x)
p = self.pool(c)
return c, p
class Encoder3D(nn.Module):
def __init__(self, in_channels):
super(Encoder3D, self).__init__()
self.conv = DoubleConvSame3D(c_in=in_channels, c_out=in_channels * 2)
self.pool = nn.MaxPool3d(kernel_size=2, stride=2)
def forward(self, x):
c = self.conv(x)
p = self.pool(c)
return c, p