Shortcuts

mmedit.models.base_archs.resnet

Module Contents

Classes

BasicBlock

Basic block for ResNet.

Bottleneck

Bottleneck block for ResNet.

ResNet

General ResNet.

class mmedit.models.base_archs.resnet.BasicBlock(inplanes: int, planes: int, stride: int = 1, dilation: int = 1, downsample: Optional[torch.nn.Module] = None, act_cfg: dict = dict(type='ReLU'), conv_cfg: Optional[dict] = None, norm_cfg: dict = dict(type='BN'), with_cp: bool = False)[源代码]

Bases: torch.nn.Module

Basic block for ResNet.

参数
  • inplanes (int) – Number of input channels.

  • planes (int) – Number of output channels.

  • stride (int) – Stride of the first block of one stage. Default: 1.

  • dilation (int) – Dilation of one stage. Default: 1.

  • downsample (nn.Module) – Downsample module. Default: None.

  • act_cfg (dict) – Dictionary to construct and config activation layer. Default: dict(type=’ReLU’).

  • conv_cfg (dict) – Dictionary to construct and config convolution layer. Default: None.

  • norm_cfg (dict) – Dictionary to construct and config norm layer. Default: dict(type=’BN’).

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

property norm1: torch.nn.Module[源代码]

normalization layer after the first convolution layer

Type

nn.Module

property norm2: torch.nn.Module[源代码]

normalization layer after the second convolution layer

Type

nn.Module

expansion = 1[源代码]
forward(x: torch.Tensor) torch.Tensor[源代码]

Forward function.

class mmedit.models.base_archs.resnet.Bottleneck(inplanes: int, planes: int, stride: int = 1, dilation: int = 1, downsample: Optional[torch.nn.Module] = None, act_cfg: dict = dict(type='ReLU'), conv_cfg: Optional[dict] = None, norm_cfg: dict = dict(type='BN'), with_cp: bool = False)[源代码]

Bases: torch.nn.Module

Bottleneck block for ResNet.

参数
  • inplanes (int) – Number of input channels.

  • planes (int) – Number of output channels.

  • stride (int) – Stride of the first block of one stage. Default: 1.

  • dilation (int) – Dilation of one stage. Default: 1.

  • downsample (nn.Module) – Downsample module. Default: None.

  • act_cfg (dict) – Dictionary to construct and config activation layer. Default: dict(type=’ReLU’).

  • conv_cfg (dict) – Dictionary to construct and config convolution layer. Default: None.

  • norm_cfg (dict) – Dictionary to construct and config norm layer. Default: dict(type=’BN’).

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

property norm1: torch.nn.Module[源代码]

normalization layer after the first convolution layer

Type

nn.Module

property norm2: torch.nn.Module[源代码]

normalization layer after the second convolution layer

Type

nn.Module

property norm3: torch.nn.Module[源代码]

normalization layer after the second convolution layer

Type

nn.Module

expansion = 4[源代码]
forward(x: torch.Tensor) torch.Tensor[源代码]
class mmedit.models.base_archs.resnet.ResNet(depth: int, in_channels: int = 3, stem_channels: int = 64, base_channels: int = 64, num_stages: int = 4, strides: Sequence[int] = (1, 2, 2, 2), dilations: Sequence[int] = (1, 1, 2, 4), deep_stem: bool = False, avg_down: bool = False, frozen_stages: int = - 1, act_cfg: dict = dict(type='ReLU'), conv_cfg: Optional[dict] = None, norm_cfg: dict = dict(type='BN'), with_cp: bool = False, multi_grid: Optional[Sequence[int]] = None, contract_dilation: bool = False, zero_init_residual: bool = True)[源代码]

Bases: torch.nn.Module

General ResNet.

This class is adopted from https://github.com/open-mmlab/mmsegmentation/blob/master/mmseg/models/backbones/resnet.py.

参数
  • depth (int) – Depth of resnet, from {18, 34, 50, 101, 152}.

  • in_channels (int) – Number of input image channels. Default” 3.

  • stem_channels (int) – Number of stem channels. Default: 64.

  • base_channels (int) – Number of base channels of res layer. Default: 64.

  • num_stages (int) – Resnet stages, normally 4.

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

  • dilations (Sequence[int]) – Dilation of each stage. Default: (1, 1, 2, 4).

  • deep_stem (bool) – Replace 7x7 conv in input stem with 3 3x3 conv. Default: False.

  • avg_down (bool) – Use AvgPool instead of stride conv when downsampling in the bottleneck. Default: False.

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

  • act_cfg (dict) – Dictionary to construct and config activation layer. Default: dict(type=’ReLU’).

  • conv_cfg (dict) – Dictionary to construct and config convolution layer. Default: None.

  • norm_cfg (dict) – Dictionary to construct and config norm layer. Default: dict(type=’BN’).

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

  • multi_grid (Sequence[int]|None) – Multi grid dilation rates of last stage. Default: None.

  • contract_dilation (bool) – Whether contract first dilation of each layer Default: False.

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

property norm1: torch.nn.Module[源代码]

normalization layer after the second convolution layer

Type

nn.Module

arch_settings[源代码]
_make_stem_layer(in_channels: int, stem_channels: int) None[源代码]

Make stem layer for ResNet.

_make_layer(block: BasicBlock, planes: int, blocks: int, stride: int = 1, dilation: int = 1) torch.nn.Module[源代码]
_nostride_dilate(m: torch.nn.Module, dilate: int) None[源代码]
init_weights(pretrained: Optional[str] = None) None[源代码]

Init weights for the model.

参数

pretrained (str, optional) – Path for pretrained weights. If given None, pretrained weights will not be loaded. Defaults to None.

_freeze_stages() None[源代码]

Freeze stages param and norm stats.

forward(x: torch.Tensor) List[torch.Tensor][源代码]

Forward function.

参数

x (Tensor) – Input tensor with shape (N, C, H, W).

返回

Output tensor.

返回类型

Tensor

Read the Docs v: latest
Versions
master
latest
stable
zyh-doc-notfound-extend
Downloads
pdf
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.