Shortcuts

Res2Net

class mmpretrain.models.backbones.Res2Net(scales=4, base_width=26, style='pytorch', deep_stem=True, avg_down=True, init_cfg=None, **kwargs)[源代码]

Res2Net backbone.

A PyTorch implement of : Res2Net: A New Multi-scale Backbone Architecture

参数:
  • depth (int) – Depth of Res2Net, choose from {50, 101, 152}.

  • scales (int) – Scales used in Res2Net. Defaults to 4.

  • base_width (int) – Basic width of each scale. Defaults to 26.

  • in_channels (int) – Number of input image channels. Defaults to 3.

  • num_stages (int) – Number of Res2Net stages. Defaults to 4.

  • strides (Sequence[int]) – Strides of the first block of each stage. Defaults to (1, 2, 2, 2).

  • dilations (Sequence[int]) – Dilation of each stage. Defaults to (1, 1, 1, 1).

  • out_indices (Sequence[int]) – Output from which stages. Defaults to (3, ).

  • style (str) – “pytorch” or “caffe”. If set to “pytorch”, the stride-two layer is the 3x3 conv layer, otherwise the stride-two layer is the first 1x1 conv layer. Defaults to “pytorch”.

  • deep_stem (bool) – Replace 7x7 conv in input stem with 3 3x3 conv. Defaults to True.

  • avg_down (bool) – Use AvgPool instead of stride conv when downsampling in the bottle2neck. Defaults to True.

  • frozen_stages (int) – Stages to be frozen (stop grad and set eval mode). -1 means not freezing any parameters. Defaults to -1.

  • norm_cfg (dict) – Dictionary to construct and config norm layer. Defaults to dict(type='BN', requires_grad=True).

  • norm_eval (bool) – Whether to set norm layers to eval mode, namely, freeze running stats (mean and var). Note: Effect on Batch Norm and its variants only. Defaults to False.

  • with_cp (bool) – Use checkpoint or not. Using checkpoint will save some memory while slowing down the training speed. Defaults to False.

  • zero_init_residual (bool) – Whether to use zero init for last norm layer in resblocks to let them behave as identity. Defaults to True.

  • init_cfg (dict or list[dict], optional) – Initialization config dict. Defaults to None.

示例

>>> from mmpretrain.models import Res2Net
>>> import torch
>>> model = Res2Net(depth=50,
...                 scales=4,
...                 base_width=26,
...                 out_indices=(0, 1, 2, 3))
>>> model.eval()
>>> inputs = torch.rand(1, 3, 32, 32)
>>> level_outputs = model.forward(inputs)
>>> for level_out in level_outputs:
...     print(tuple(level_out.shape))
(1, 256, 8, 8)
(1, 512, 4, 4)
(1, 1024, 2, 2)
(1, 2048, 1, 1)
Read the Docs v: latest
Versions
latest
stable
mmcls-1.x
mmcls-0.x
dev
Downloads
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.