(self,
depth,
in_channels=3,
stem_channels=64,
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=False,
dcn=None,
stage_with_dcn=(False, False, False, False),
plugins=None,
multi_grid=None,
contract_dilation=False,
with_cp=False,
zero_init_residual=True,
pretrained=None,
init_cfg=None)
| 394 | } |
| 395 | |
| 396 | def __init__(self, |
| 397 | depth, |
| 398 | in_channels=3, |
| 399 | stem_channels=64, |
| 400 | base_channels=64, |
| 401 | num_stages=4, |
| 402 | strides=(1, 2, 2, 2), |
| 403 | dilations=(1, 1, 1, 1), |
| 404 | out_indices=(0, 1, 2, 3), |
| 405 | style='pytorch', |
| 406 | deep_stem=False, |
| 407 | avg_down=False, |
| 408 | frozen_stages=-1, |
| 409 | conv_cfg=None, |
| 410 | norm_cfg=dict(type='BN', requires_grad=True), |
| 411 | norm_eval=False, |
| 412 | dcn=None, |
| 413 | stage_with_dcn=(False, False, False, False), |
| 414 | plugins=None, |
| 415 | multi_grid=None, |
| 416 | contract_dilation=False, |
| 417 | with_cp=False, |
| 418 | zero_init_residual=True, |
| 419 | pretrained=None, |
| 420 | init_cfg=None): |
| 421 | super(ResNet, self).__init__(init_cfg) |
| 422 | if depth not in self.arch_settings: |
| 423 | raise KeyError(f'invalid depth {depth} for resnet') |
| 424 | |
| 425 | self.pretrained = pretrained |
| 426 | self.zero_init_residual = zero_init_residual |
| 427 | block_init_cfg = None |
| 428 | assert not (init_cfg and pretrained), \ |
| 429 | 'init_cfg and pretrained cannot be setting at the same time' |
| 430 | if isinstance(pretrained, str): |
| 431 | warnings.warn('DeprecationWarning: pretrained is a deprecated, ' |
| 432 | 'please use "init_cfg" instead') |
| 433 | self.init_cfg = dict(type='Pretrained', checkpoint=pretrained) |
| 434 | elif pretrained is None: |
| 435 | if init_cfg is None: |
| 436 | self.init_cfg = [ |
| 437 | dict(type='Kaiming', layer='Conv2d'), |
| 438 | dict( |
| 439 | type='Constant', |
| 440 | val=1, |
| 441 | layer=['_BatchNorm', 'GroupNorm']) |
| 442 | ] |
| 443 | block = self.arch_settings[depth][0] |
| 444 | if self.zero_init_residual: |
| 445 | if block is BasicBlock: |
| 446 | block_init_cfg = dict( |
| 447 | type='Constant', |
| 448 | val=0, |
| 449 | override=dict(name='norm2')) |
| 450 | elif block is Bottleneck: |
| 451 | block_init_cfg = dict( |
| 452 | type='Constant', |
| 453 | val=0, |
no test coverage detected