MCPcopy Create free account
hub / github.com/alinlab/SelfPatch / __init__

Method __init__

segmentation/backbones/hrnet.py:299–422  ·  view source on GitHub ↗
(self,
                 extra,
                 in_channels=3,
                 conv_cfg=None,
                 norm_cfg=dict(type='BN', requires_grad=True),
                 norm_eval=False,
                 with_cp=False,
                 frozen_stages=-1,
                 zero_init_residual=False,
                 multiscale_output=True,
                 pretrained=None,
                 init_cfg=None)

Source from the content-addressed store, hash-verified

297 blocks_dict = {'BASIC': BasicBlock, 'BOTTLENECK': Bottleneck}
298
299 def __init__(self,
300 extra,
301 in_channels=3,
302 conv_cfg=None,
303 norm_cfg=dict(type='BN', requires_grad=True),
304 norm_eval=False,
305 with_cp=False,
306 frozen_stages=-1,
307 zero_init_residual=False,
308 multiscale_output=True,
309 pretrained=None,
310 init_cfg=None):
311 super(HRNet, self).__init__(init_cfg)
312
313 self.pretrained = pretrained
314 self.zero_init_residual = zero_init_residual
315 assert not (init_cfg and pretrained), \
316 'init_cfg and pretrained cannot be setting at the same time'
317 if isinstance(pretrained, str):
318 warnings.warn('DeprecationWarning: pretrained is deprecated, '
319 'please use "init_cfg" instead')
320 self.init_cfg = dict(type='Pretrained', checkpoint=pretrained)
321 elif pretrained is None:
322 if init_cfg is None:
323 self.init_cfg = [
324 dict(type='Kaiming', layer='Conv2d'),
325 dict(
326 type='Constant',
327 val=1,
328 layer=['_BatchNorm', 'GroupNorm'])
329 ]
330 else:
331 raise TypeError('pretrained must be a str or None')
332
333 # Assert configurations of 4 stages are in extra
334 assert 'stage1' in extra and 'stage2' in extra \
335 and 'stage3' in extra and 'stage4' in extra
336 # Assert whether the length of `num_blocks` and `num_channels` are
337 # equal to `num_branches`
338 for i in range(4):
339 cfg = extra[f'stage{i + 1}']
340 assert len(cfg['num_blocks']) == cfg['num_branches'] and \
341 len(cfg['num_channels']) == cfg['num_branches']
342
343 self.extra = extra
344 self.conv_cfg = conv_cfg
345 self.norm_cfg = norm_cfg
346 self.norm_eval = norm_eval
347 self.with_cp = with_cp
348 self.frozen_stages = frozen_stages
349
350 # stem net
351 self.norm1_name, norm1 = build_norm_layer(self.norm_cfg, 64, postfix=1)
352 self.norm2_name, norm2 = build_norm_layer(self.norm_cfg, 64, postfix=2)
353
354 self.conv1 = build_conv_layer(
355 self.conv_cfg,
356 in_channels,

Callers 1

__init__Method · 0.45

Calls 4

_make_layerMethod · 0.95
_make_stageMethod · 0.95
_freeze_stagesMethod · 0.95

Tested by

no test coverage detected