MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / __init__

Method __init__

detrsmpl/models/backbones/resnet.py:359–478  ·  view source on GitHub ↗
(self,
                 depth,
                 in_channels=3,
                 stem_channels=None,
                 base_channels=64,
                 num_stages=4,
                 strides=(1, 2, 2, 2),
                 dilations=(1, 1, 1, 1),
                 out_indices=(0, 1, 2, 3),
                 style='pytorch',
                 deep_stem=False,
                 avg_down=False,
                 frozen_stages=-1,
                 conv_cfg=None,
                 norm_cfg=dict(type='BN', requires_grad=True),
                 norm_eval=True,
                 dcn=None,
                 stage_with_dcn=(False, False, False, False),
                 plugins=None,
                 with_cp=False,
                 zero_init_residual=True,
                 pretrained=None,
                 init_cfg=None)

Source from the content-addressed store, hash-verified

357 }
358
359 def __init__(self,
360 depth,
361 in_channels=3,
362 stem_channels=None,
363 base_channels=64,
364 num_stages=4,
365 strides=(1, 2, 2, 2),
366 dilations=(1, 1, 1, 1),
367 out_indices=(0, 1, 2, 3),
368 style='pytorch',
369 deep_stem=False,
370 avg_down=False,
371 frozen_stages=-1,
372 conv_cfg=None,
373 norm_cfg=dict(type='BN', requires_grad=True),
374 norm_eval=True,
375 dcn=None,
376 stage_with_dcn=(False, False, False, False),
377 plugins=None,
378 with_cp=False,
379 zero_init_residual=True,
380 pretrained=None,
381 init_cfg=None):
382 super(ResNet, self).__init__(init_cfg)
383 self.zero_init_residual = zero_init_residual
384 if depth not in self.arch_settings:
385 raise KeyError(f'invalid depth {depth} for resnet')
386
387 block_init_cfg = None
388 assert not (init_cfg and pretrained), \
389 'init_cfg and pretrained cannot be setting at the same time'
390 if isinstance(pretrained, str):
391 warnings.warn('DeprecationWarning: pretrained is deprecated, '
392 'please use "init_cfg" instead')
393 self.init_cfg = dict(type='Pretrained', checkpoint=pretrained)
394 elif pretrained is None:
395 if init_cfg is None:
396 self.init_cfg = [
397 dict(type='Kaiming', layer='Conv2d'),
398 dict(type='Constant',
399 val=1,
400 layer=['_BatchNorm', 'GroupNorm'])
401 ]
402 block = self.arch_settings[depth][0]
403 if self.zero_init_residual:
404 if block is BasicBlock:
405 block_init_cfg = dict(type='Constant',
406 val=0,
407 override=dict(name='norm2'))
408 elif block is Bottleneck:
409 block_init_cfg = dict(type='Constant',
410 val=0,
411 override=dict(name='norm3'))
412 else:
413 raise TypeError('pretrained must be a str or None')
414
415 self.depth = depth
416 if stem_channels is None:

Callers 3

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 4

_make_stem_layerMethod · 0.95
make_stage_pluginsMethod · 0.95
make_res_layerMethod · 0.95
_freeze_stagesMethod · 0.95

Tested by

no test coverage detected