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

Class ResNet

segmentation/backbones/resnet.py:311–685  ·  view source on GitHub ↗

ResNet backbone. This backbone is the improved implementation of `Deep Residual Learning for Image Recognition `_. Args: depth (int): Depth of resnet, from {18, 34, 50, 101, 152}. in_channels (int): Number of input image channels. Defau

Source from the content-addressed store, hash-verified

309
310@BACKBONES.register_module()
311class ResNet(BaseModule):
312 """ResNet backbone.
313
314 This backbone is the improved implementation of `Deep Residual Learning
315 for Image Recognition <https://arxiv.org/abs/1512.03385>`_.
316
317 Args:
318 depth (int): Depth of resnet, from {18, 34, 50, 101, 152}.
319 in_channels (int): Number of input image channels. Default: 3.
320 stem_channels (int): Number of stem channels. Default: 64.
321 base_channels (int): Number of base channels of res layer. Default: 64.
322 num_stages (int): Resnet stages, normally 4. Default: 4.
323 strides (Sequence[int]): Strides of the first block of each stage.
324 Default: (1, 2, 2, 2).
325 dilations (Sequence[int]): Dilation of each stage.
326 Default: (1, 1, 1, 1).
327 out_indices (Sequence[int]): Output from which stages.
328 Default: (0, 1, 2, 3).
329 style (str): `pytorch` or `caffe`. If set to "pytorch", the stride-two
330 layer is the 3x3 conv layer, otherwise the stride-two layer is
331 the first 1x1 conv layer. Default: 'pytorch'.
332 deep_stem (bool): Replace 7x7 conv in input stem with 3 3x3 conv.
333 Default: False.
334 avg_down (bool): Use AvgPool instead of stride conv when
335 downsampling in the bottleneck. Default: False.
336 frozen_stages (int): Stages to be frozen (stop grad and set eval mode).
337 -1 means not freezing any parameters. Default: -1.
338 conv_cfg (dict | None): Dictionary to construct and config conv layer.
339 When conv_cfg is None, cfg will be set to dict(type='Conv2d').
340 Default: None.
341 norm_cfg (dict): Dictionary to construct and config norm layer.
342 Default: dict(type='BN', requires_grad=True).
343 norm_eval (bool): Whether to set norm layers to eval mode, namely,
344 freeze running stats (mean and var). Note: Effect on Batch Norm
345 and its variants only. Default: False.
346 dcn (dict | None): Dictionary to construct and config DCN conv layer.
347 When dcn is not None, conv_cfg must be None. Default: None.
348 stage_with_dcn (Sequence[bool]): Whether to set DCN conv for each
349 stage. The length of stage_with_dcn is equal to num_stages.
350 Default: (False, False, False, False).
351 plugins (list[dict]): List of plugins for stages, each dict contains:
352
353 - cfg (dict, required): Cfg dict to build plugin.
354
355 - position (str, required): Position inside block to insert plugin,
356 options: 'after_conv1', 'after_conv2', 'after_conv3'.
357
358 - stages (tuple[bool], optional): Stages to apply plugin, length
359 should be same as 'num_stages'.
360 Default: None.
361 multi_grid (Sequence[int]|None): Multi grid dilation rates of last
362 stage. Default: None.
363 contract_dilation (bool): Whether contract first dilation of each layer
364 Default: False.
365 with_cp (bool): Use checkpoint or not. Using checkpoint will save some
366 memory while slowing down the training speed. Default: False.
367 zero_init_residual (bool): Whether to use zero init for last norm layer
368 in resblocks to let them behave as identity. Default: True.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected