MCPcopy Create free account
hub / github.com/AtlasAnalyticsLab/AdaFisher / Bottleneck

Class Bottleneck

Image_Classification/src/models/resnet.py:89–135  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

87
88
89class Bottleneck(nn.Module):
90 # Bottleneck in torchvision places the stride for downsampling at 3x3 convolution(self.conv2)
91 # while original implementation places the stride at the first 1x1 convolution(self.conv1)
92 # according to "Deep residual learning for image recognition"https://arxiv.org/abs/1512.03385.
93 # This variant is also known as ResNet V1.5 and improves accuracy according to
94 # https://ngc.nvidia.com/catalog/model-scripts/nvidia:resnet_50_v1_5_for_pytorch.
95
96 expansion = 4
97
98 def __init__(self, inplanes, planes, stride=1, downsample=None, groups=1,
99 base_width=64, dilation=1, norm_layer=None):
100 super(Bottleneck, self).__init__()
101 if norm_layer is None:
102 norm_layer = nn.BatchNorm2d
103 width = int(planes * (base_width / 64.)) * groups
104 # Both self.conv2 and self.downsample layers downsample the input when stride != 1
105 self.conv1 = conv1x1(inplanes, width)
106 self.bn1 = norm_layer(width)
107 self.conv2 = conv3x3(width, width, stride, groups, dilation)
108 self.bn2 = norm_layer(width)
109 self.conv3 = conv1x1(width, planes * self.expansion)
110 self.bn3 = norm_layer(planes * self.expansion)
111 self.relu = nn.ReLU(inplace=False)
112 self.downsample = downsample
113 self.stride = stride
114
115 def forward(self, x):
116 identity = x
117
118 out = self.conv1(x)
119 out = self.bn1(out)
120 out = self.relu(out)
121
122 out = self.conv2(out)
123 out = self.bn2(out)
124 out = self.relu(out)
125
126 out = self.conv3(out)
127 out = self.bn3(out)
128
129 if self.downsample is not None:
130 identity = self.downsample(x)
131
132 out = out + identity
133 out = self.relu(out)
134
135 return out
136
137
138class ResNet(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected