MCPcopy Create free account
hub / github.com/Sirwenhao/Deep-Learning-Notes / Bottleneck

Class Bottleneck

CV/Pytorch_classification/ResNet/model.py:40–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38 return out
39
40class Bottleneck(nn.Module):
41 expansion = 4
42
43 def __init__(self, in_channel, out_channel, stride=1, downsample=None, groups=1, width_per_group=64):
44 super(Bottleneck, self).__init__()
45
46 width = int(out_channel * (width_per_group / 64.)) * groups
47
48 self.conv1 = nn.Conv2d(in_channels=in_channel, out_channels=width,
49 kernel_size=1, stride=1, bias=False)
50
51 self.bn1 = nn.BatchNorm2d(width)
52
53 self.conv2 = nn.Conv2d(in_channels=width, out_channels=width, groups=groups,
54 kernel_size=3, stride=stride, bias=False, padding=1)
55
56 self.bn2 = nn.BatchNorm2d(width)
57
58 self.conv3 = nn.Conv2d(in_channels=width, out_channels=out_channel*self.expansion,
59 kernel_size=1, stride=1, bias=False)
60 self.bn3 = nn.BatchNorm2d(out_channel*self.expansion)
61 self.relu = nn.ReLU(inplace=True)
62 self.downsample = downsample
63
64 def forward(self, x):
65 identity = x
66 if self.downsample is not None:
67 identity = self.downsample(x)
68
69 out = self.conv1(x)
70 out = self.bn1(out)
71 out = self.relu(out)
72
73 out = self.conv2(out)
74 out = self.bn2(out)
75 out = self.relu(out)
76
77 out = self.conv3(out)
78 out = self.bn3(out)
79
80 out += identity
81 out = self.relu(out)
82
83 return out
84
85class ResNet(nn.Module):
86 def __init__(self,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected