Args: input_ch(int) : the number of input channel out_features (list[str]): name of the layers whose outputs should be returned in forward. Can be anything in "stem", "stage2" ...
(self, spec_name, input_ch=3, out_features=None,
frozen_stages=-1, norm_eval=True, pretrained=None, init_cfg=None)
| 268 | @BACKBONES.register_module() |
| 269 | class VoVNet(BaseModule): |
| 270 | def __init__(self, spec_name, input_ch=3, out_features=None, |
| 271 | frozen_stages=-1, norm_eval=True, pretrained=None, init_cfg=None): |
| 272 | """ |
| 273 | Args: |
| 274 | input_ch(int) : the number of input channel |
| 275 | out_features (list[str]): name of the layers whose outputs should |
| 276 | be returned in forward. Can be anything in "stem", "stage2" ... |
| 277 | """ |
| 278 | super(VoVNet, self).__init__(init_cfg) |
| 279 | self.frozen_stages = frozen_stages |
| 280 | self.norm_eval = norm_eval |
| 281 | |
| 282 | if isinstance(pretrained, str): |
| 283 | warnings.warn('DeprecationWarning: pretrained is deprecated, ' |
| 284 | 'please use "init_cfg" instead') |
| 285 | self.init_cfg = dict(type='Pretrained', checkpoint=pretrained) |
| 286 | stage_specs = _STAGE_SPECS[spec_name] |
| 287 | |
| 288 | stem_ch = stage_specs["stem"] |
| 289 | config_stage_ch = stage_specs["stage_conv_ch"] |
| 290 | config_concat_ch = stage_specs["stage_out_ch"] |
| 291 | block_per_stage = stage_specs["block_per_stage"] |
| 292 | layer_per_block = stage_specs["layer_per_block"] |
| 293 | SE = stage_specs["eSE"] |
| 294 | depthwise = stage_specs["dw"] |
| 295 | |
| 296 | self._out_features = out_features |
| 297 | |
| 298 | # Stem module |
| 299 | conv_type = dw_conv3x3 if depthwise else conv3x3 |
| 300 | stem = conv3x3(input_ch, stem_ch[0], "stem", "1", 2) |
| 301 | stem += conv_type(stem_ch[0], stem_ch[1], "stem", "2", 1) |
| 302 | stem += conv_type(stem_ch[1], stem_ch[2], "stem", "3", 2) |
| 303 | self.add_module("stem", nn.Sequential((OrderedDict(stem)))) |
| 304 | current_stirde = 4 |
| 305 | self._out_feature_strides = {"stem": current_stirde, "stage2": current_stirde} |
| 306 | self._out_feature_channels = {"stem": stem_ch[2]} |
| 307 | |
| 308 | stem_out_ch = [stem_ch[2]] |
| 309 | in_ch_list = stem_out_ch + config_concat_ch[:-1] |
| 310 | # OSA stages |
| 311 | self.stage_names = [] |
| 312 | for i in range(4): # num_stages |
| 313 | name = "stage%d" % (i + 2) # stage 2 ... stage 5 |
| 314 | self.stage_names.append(name) |
| 315 | self.add_module( |
| 316 | name, |
| 317 | _OSA_stage( |
| 318 | in_ch_list[i], |
| 319 | config_stage_ch[i], |
| 320 | config_concat_ch[i], |
| 321 | block_per_stage[i], |
| 322 | layer_per_block, |
| 323 | i + 2, |
| 324 | SE, |
| 325 | depthwise, |
| 326 | ), |
| 327 | ) |