class_docstr: Context Guided Block for CGNet.
  
  This class consists of four components: local feature extractor,
  surrounding feature extractor, joint feature extractor and global
  context extractor.
  
  Args:
      in_channels (int): Number of input feature channels.
      out_channels (int): Number of output feature channels.
      dilation (int): Dilation rate for surrounding context extractor.
          Default: 2.
      reduction (int): Reduction for global context extractor. Default: 16.
      skip_connect (bool): Add input to output or not. Default: True.
      downsample (bool): Downsample the input to 1/2 or not. Default: False.
      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').
      with_cp (bool): Use checkpoint or not. Using checkpoint will save some
          memory while slowing down the training speed. Default: False.
class_docstr_tok: ["Context","Guided","Block","for","CGNet",".","This","class","consists","of","four","components",":","local","feature","extractor",",","surrounding","feature","extractor",",","joint","feature","extractor","and","global","context","extractor",".","Args",":","in_channels","(","int",")",":","Number","of","input","feature","channels",".","out_channels","(","int",")",":","Number","of","output","feature","channels",".","dilation","(","int",")",":","Dilation","rate","for","surrounding","context","extractor",".","Default",":","2.","reduction","(","int",")",":","Reduction","for","global","context","extractor",".","Default",":","16.","skip_connect","(","bool",")",":","Add","input","to","output","or","not",".","Default",":","True",".","downsample","(","bool",")",":","Downsample","the","input","to","1\/2","or","not",".","Default",":","False",".","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","'",")",".","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,
      out_channels,
      dilation=2,
      reduction=16,
      skip_connect=True,
      downsample=False,
      conv_cfg=None,
      norm_cfg=dict(type="BN", requires_grad=True),
      act_cfg=dict(type="PReLU"),
      with_cp=False,
  ):
      super(ContextGuidedBlock, self).__init__()
      self.with_cp = with_cp
      self.downsample = downsample
  
      channels = out_channels if downsample else out_channels // 2
      if "type" in act_cfg and act_cfg["type"] == "PReLU":
          act_cfg["num_parameters"] = channels
      kernel_size = 3 if downsample else 1
      stride = 2 if downsample else 1
      padding = (kernel_size - 1) // 2
  
      self.conv1x1 = ConvModule(
          in_channels,
          channels,
          kernel_size,
          stride,
          padding,
          conv_cfg=conv_cfg,
          norm_cfg=norm_cfg,
          act_cfg=act_cfg,
      )
  
      self.f_loc = build_conv_layer(
          conv_cfg,
          channels,
          channels,
          kernel_size=3,
          padding=1,
          groups=channels,
          bias=False,
      )
      self.f_sur = build_conv_layer(
          conv_cfg,
          channels,
          channels,
          kernel_size=3,
          padding=dilation,
          groups=channels,
          dilation=dilation,
          bias=False,
      )
  
      self.bn = build_norm_layer(norm_cfg, 2 * channels)[1]
      self.activate = nn.PReLU(2 * channels)
  
      if downsample:
          self.bottleneck = build_conv_layer(
              conv_cfg,
              2 * channels,
              out_channels,
              kernel_size=1,
              bias=False,
          )
  
      self.skip_connect = skip_connect and not downsample
      self.f_glo = GlobalContextExtractor(
          out_channels, reduction, with_cp
      )
  
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 ContextGuidedBlock object from inherited base classes: nn with example: obj = ContextGuidedBlock(in_channels, out_channels, dilation, reduction, skip_connect, downsample, conv_cfg, norm_cfg, act_cfg, with_cp)