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

Class Bottlneck

CV/Pytorch_classification/RegNet/model.py:139–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137 return scale * x
138
139class Bottlneck():
140 def __init__(self,
141 in_c,
142 out_c,
143 stride = 1,
144 group_width = 1,
145 se_ratio = 0.,
146 drop_ratio = 0.):
147 super(Bottlneck, self).__init__()
148
149 self.conv1 = ConvBNAct(in_c=in_c, out_c=out_c, kernel_s=1)
150 self.conv2 = ConvBNAct(in_c=out_c,
151 out_c=out_c,
152 kernel_s=3,
153 stride=stride,
154 padding=1,
155 groups=out_c // group_width)
156
157 if se_ratio > 0:
158 self.se = SqueezeExcitation(in_c, se_ratio)
159 else:
160 self.se = nn.Identity()
161
162 self.conv3 = ConvBNAct(in_c=out_c, out_c=out_c, kernel_s=1, act=None)
163 self.ac3 = nn.ReLU(inplace=True)
164
165 if drop_ratio > 0:
166 self.dropout = nn.Dropout(p=drop_ratio)
167 else:
168 self.dropout = nn.Identity()
169
170 if (in_c != out_c) or (stride != 1):
171 self.downsample = ConvBNAct(in_c=in_c, out_c=out_c, kernel_s=1, stride=stride, act=None)
172 else:
173 self.downsample = nn.Identity()
174
175 def zero_init_last_bn(self):
176 nn.init.zeros_(self.conv3.bn.weight)
177
178 def forward(self):
179 shortcut = x
180 x = self.conv1(x)
181 x = self.conv2(x)
182
183 x = self.se(x)
184 x = self.conv3(x)
185
186 x = self.dropout(x)
187
188 shortcut = self.downsample(shortcut)
189
190 x += shortcut
191 x = self.ac3(x)
192 return x
193
194class RegStage(nn.Moduel):
195 def __init__(self,

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected