class_docstr: CGNet backbone.
  
  A Light-weight Context Guided Network for Semantic Segmentation
  arXiv: https://arxiv.org/abs/1811.08201
  
  Args:
      in_channels (int): Number of input image channels. Normally 3.
      num_channels (tuple[int]): Numbers of feature channels at each stages.
          Default: (32, 64, 128).
      num_blocks (tuple[int]): Numbers of CG blocks at stage 1 and stage 2.
          Default: (3, 21).
      dilations (tuple[int]): Dilation rate for surrounding context
          extractors at stage 1 and stage 2. Default: (2, 4).
      reductions (tuple[int]): Reductions for global context extractors at
          stage 1 and stage 2. Default: (8, 16).
      conv_cfg (dict): Config dict for convolution layer.
          Default: None, which means using conv2d.
      norm_cfg (dict): Config dict for normalization layer.
          Default: dict(type='BN', requires_grad=True).
      act_cfg (dict): Config dict for activation layer.
          Default: dict(type='PReLU').
      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. Default: False.
      with_cp (bool): Use checkpoint or not. Using checkpoint will save some
          memory while slowing down the training speed. Default: False.
class_docstr_tok: ["CGNet","backbone",".","A","Light-weight","Context","Guided","Network","for","Semantic","Segmentation","arXiv",":","https",":","\/\/arxiv.org\/abs\/1811.08201","Args",":","in_channels","(","int",")",":","Number","of","input","image","channels",".","Normally","3.","num_channels","(","tuple","[","int","]",")",":","Numbers","of","feature","channels","at","each","stages",".","Default",":","(","32",",","64",",","128",")",".","num_blocks","(","tuple","[","int","]",")",":","Numbers","of","CG","blocks","at","stage","1","and","stage","2",".","Default",":","(","3",",","21",")",".","dilations","(","tuple","[","int","]",")",":","Dilation","rate","for","surrounding","context","extractors","at","stage","1","and","stage","2",".","Default",":","(","2",",","4",")",".","reductions","(","tuple","[","int","]",")",":","Reductions","for","global","context","extractors","at","stage","1","and","stage","2",".","Default",":","(","8",",","16",")",".","conv_cfg","(","dict",")",":","Config","dict","for","convolution","layer",".","Default",":","None",",","which","means","using","conv2d",".","norm_cfg","(","dict",")",":","Config","dict","for","normalization","layer",".","Default",":","dict","(","type='BN","'",",","requires_grad=True",")",".","act_cfg","(","dict",")",":","Config","dict","for","activation","layer",".","Default",":","dict","(","type='PReLU","'",")",".","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",".","Default",":","False",".","with_cp","(","bool",")",":","Use","checkpoint","or","not",".","Using","checkpoint","will","save","some","memory","while","slowing","down","the","training","speed",".","Default",":","False","."]
code: def __init__(
      self,
      in_channels=3,
      num_channels=(32, 64, 128),
      num_blocks=(3, 21),
      dilations=(2, 4),
      reductions=(8, 16),
      conv_cfg=None,
      norm_cfg=dict(type="BN", requires_grad=True),
      act_cfg=dict(type="PReLU"),
      norm_eval=False,
      with_cp=False,
  ):
      super(CGNet, self).__init__()
      self.in_channels = in_channels
      self.num_channels = num_channels
      assert (
          isinstance(self.num_channels, tuple)
          and len(self.num_channels) == 3
      )
      self.num_blocks = num_blocks
      assert (
          isinstance(self.num_blocks, tuple)
          and len(self.num_blocks) == 2
      )
      self.dilations = dilations
      assert (
          isinstance(self.dilations, tuple) and len(self.dilations) == 2
      )
      self.reductions = reductions
      assert (
          isinstance(self.reductions, tuple)
          and len(self.reductions) == 2
      )
      self.conv_cfg = conv_cfg
      self.norm_cfg = norm_cfg
      self.act_cfg = act_cfg
      if "type" in self.act_cfg and self.act_cfg["type"] == "PReLU":
          self.act_cfg["num_parameters"] = num_channels[0]
      self.norm_eval = norm_eval
      self.with_cp = with_cp
  
      cur_channels = in_channels
      self.stem = nn.ModuleList()
      for i in range(3):
          self.stem.append(
              ConvModule(
                  cur_channels,
                  num_channels[0],
                  3,
                  2 if i == 0 else 1,
                  padding=1,
                  conv_cfg=conv_cfg,
                  norm_cfg=norm_cfg,
                  act_cfg=act_cfg,
              )
          )
          cur_channels = num_channels[0]
  
      self.inject_2x = InputInjection(
          1
      )  # down-sample for Input, factor=2
      self.inject_4x = InputInjection(
          2
      )  # down-sample for Input, factor=4
  
      cur_channels += in_channels
      self.norm_prelu_0 = nn.Sequential(
          build_norm_layer(norm_cfg, cur_channels)[1],
          nn.PReLU(cur_channels),
      )
  
      # stage 1
      self.level1 = nn.ModuleList()
      for i in range(num_blocks[0]):
          self.level1.append(
              ContextGuidedBlock(
                  cur_channels if i == 0 else num_channels[1],
                  num_channels[1],
                  dilations[0],
                  reductions[0],
                  downsample=(i == 0),
                  conv_cfg=conv_cfg,
                  norm_cfg=norm_cfg,
                  act_cfg=act_cfg,
                  with_cp=with_cp,
              )
          )  # CG block
  
      cur_channels = 2 * num_channels[1] + in_channels
      self.norm_prelu_1 = nn.Sequential(
          build_norm_layer(norm_cfg, cur_channels)[1],
          nn.PReLU(cur_channels),
      )
  
      # stage 2
      self.level2 = nn.ModuleList()
      for i in range(num_blocks[1]):
          self.level2.append(
              ContextGuidedBlock(
                  cur_channels if i == 0 else num_channels[2],
                  num_channels[2],
                  dilations[1],
                  reductions[1],
                  downsample=(i == 0),
                  conv_cfg=conv_cfg,
                  norm_cfg=norm_cfg,
                  act_cfg=act_cfg,
                  with_cp=with_cp,
              )
          )  # CG block
  
      cur_channels = 2 * num_channels[2]
      self.norm_prelu_2 = nn.Sequential(
          build_norm_layer(norm_cfg, cur_channels)[1],
          nn.PReLU(cur_channels),
      )
  
imports: import torch
  import torch.nn
  import torch.utils.checkpoint
  from annotator.uniformer.mmcv.cnn import ConvModule, build_conv_layer, build_norm_layer, constant_init, kaiming_init
  from annotator.uniformer.mmcv.runner import load_checkpoint
  from annotator.uniformer.mmcv.utils.parrots_wrapper import _BatchNorm
  from annotator.uniformer.mmseg.utils import get_root_logger
  from ..builder import BACKBONES
label_desc: Use image node_id 1 to create a new CGNet object from inherited base classes: nn with example: obj = CGNet(in_channels, num_channels, num_blocks, dilations, reductions, conv_cfg, norm_cfg, act_cfg, norm_eval, with_cp)