-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodules_difference.py
More file actions
50 lines (46 loc) · 1.49 KB
/
Copy pathmodules_difference.py
File metadata and controls
50 lines (46 loc) · 1.49 KB
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
# Please navigate to original modules.py and add the following code after line 178 of the original file
class Bottleneck(nn.Module):
def __init__(self, in_channels, inter_channels, identity_downsample=None, stride=1, norm="BatchNorm2d"):
super(Bottleneck, self).__init__()
self.expansion=4
bias = norm == 'none'
self.in_channels = in_channels
self.conv1 = ConvLayer(
in_channels=in_channels,
out_channels=inter_channels,
kernel_size=1,
stride=1,
padding=0,
bias=False,
norm=norm,
)
self.conv2 = ConvLayer(
in_channels=inter_channels,
out_channels=inter_channels,
kernel_size=3,
stride=stride,
padding=1,
norm=norm,
bias=False,
)
self.conv3 = ConvLayer(
in_channels=inter_channels,
out_channels=inter_channels*self.expansion,
kernel_size=1,
stride=1,
padding=0,
norm=norm,
bias=False,
)
self.identity_downsample = identity_downsample
self.stride = stride
def forward(self, x):
identity=x.clone()
out = self.conv1(x)
out = self.conv2(out)
out = self.conv3(out)
if self.identity_downsample is not None:
identity = self.identity_downsample(identity)
out += identity
out = F.relu(out)
return out