class_docstr: The RTFormer implementation based on PaddlePaddle.
  
  The original article refers to "Wang, Jian, Chenhui Gou, Qiman Wu, Haocheng Feng, 
  Junyu Han, Errui Ding, and Jingdong Wang. RTFormer: Efficient Design for Real-Time
  Semantic Segmentation with Transformer. arXiv preprint arXiv:2210.07124 (2022)."
  
  Args:
      num_classes (int): The unique number of target classes.
      layer_nums (List, optional): The layer nums of every stage. Default: [2, 2, 2, 2]
      base_channels (int, optional): The base channels. Default: 64
      spp_channels (int, optional): The channels of DAPPM. Defualt: 128
      num_heads (int, optional): The num of heads in EABlock. Default: 8
      head_channels (int, optional): The channels of head in EABlock. Default: 128
      drop_rate (float, optional): The drop rate in EABlock. Default:0.
      drop_path_rate (float, optional): The drop path rate in EABlock. Default: 0.2
      use_aux_head (bool, optional): Whether use auxiliary head. Default: True
      use_injection (list[boo], optional): Whether use injection in layer 4 and 5.
          Default: [True, True]
      lr_mult (float, optional): The multiplier of lr for DAPPM and head module. Default: 10
      cross_size (int, optional): The size of pooling in cross_kv. Default: 12
      in_channels (int, optional): The channels of input image. Default: 3
      pretrained (str, optional): The path or url of pretrained model. Default: None.
class_docstr_tok: ["The","RTFormer","implementation","based","on","PaddlePaddle",".","The","original","article","refers","to","``","Wang",",","Jian",",","Chenhui","Gou",",","Qiman","Wu",",","Haocheng","Feng",",","Junyu","Han",",","Errui","Ding",",","and","Jingdong","Wang",".","RTFormer",":","Efficient","Design","for","Real-Time","Semantic","Segmentation","with","Transformer",".","arXiv","preprint","arXiv:2210.07124","(","2022",")",".","''","Args",":","num_classes","(","int",")",":","The","unique","number","of","target","classes",".","layer_nums","(","List",",","optional",")",":","The","layer","nums","of","every","stage",".","Default",":","[","2",",","2",",","2",",","2","]","base_channels","(","int",",","optional",")",":","The","base","channels",".","Default",":","64","spp_channels","(","int",",","optional",")",":","The","channels","of","DAPPM",".","Defualt",":","128","num_heads","(","int",",","optional",")",":","The","num","of","heads","in","EABlock",".","Default",":","8","head_channels","(","int",",","optional",")",":","The","channels","of","head","in","EABlock",".","Default",":","128","drop_rate","(","float",",","optional",")",":","The","drop","rate","in","EABlock",".","Default:0.","drop_path_rate","(","float",",","optional",")",":","The","drop","path","rate","in","EABlock",".","Default",":","0.2","use_aux_head","(","bool",",","optional",")",":","Whether","use","auxiliary","head",".","Default",":","True","use_injection","(","list","[","boo","]",",","optional",")",":","Whether","use","injection","in","layer","4","and","5",".","Default",":","[","True",",","True","]","lr_mult","(","float",",","optional",")",":","The","multiplier","of","lr","for","DAPPM","and","head","module",".","Default",":","10","cross_size","(","int",",","optional",")",":","The","size","of","pooling","in","cross_kv",".","Default",":","12","in_channels","(","int",",","optional",")",":","The","channels","of","input","image",".","Default",":","3","pretrained","(","str",",","optional",")",":","The","path","or","url","of","pretrained","model",".","Default",":","None","."]
code: def __init__(
      self,
      num_classes,
      layer_nums=[2, 2, 2, 2],
      base_channels=64,
      spp_channels=128,
      num_heads=8,
      head_channels=128,
      drop_rate=0.0,
      drop_path_rate=0.2,
      use_aux_head=True,
      use_injection=[True, True],
      lr_mult=10.0,
      cross_size=12,
      in_channels=3,
      pretrained=None,
  ):
      super().__init__()
      self.base_channels = base_channels
      base_chs = base_channels
  
      self.conv1 = nn.Sequential(
          nn.Conv2D(
              in_channels, base_chs, kernel_size=3, stride=2, padding=1
          ),
          bn2d(base_chs),
          nn.ReLU(),
          nn.Conv2D(
              base_chs, base_chs, kernel_size=3, stride=2, padding=1
          ),
          bn2d(base_chs),
          nn.ReLU(),
      )
      self.relu = nn.ReLU()
  
      self.layer1 = self._make_layer(
          BasicBlock, base_chs, base_chs, layer_nums[0]
      )
      self.layer2 = self._make_layer(
          BasicBlock, base_chs, base_chs * 2, layer_nums[1], stride=2
      )
      self.layer3 = self._make_layer(
          BasicBlock,
          base_chs * 2,
          base_chs * 4,
          layer_nums[2],
          stride=2,
      )
      self.layer3_ = self._make_layer(
          BasicBlock, base_chs * 2, base_chs * 2, 1
      )
      self.compression3 = nn.Sequential(
          bn2d(base_chs * 4),
          nn.ReLU(),
          conv2d(base_chs * 4, base_chs * 2, kernel_size=1),
      )
      self.layer4 = EABlock(
          in_channels=[base_chs * 2, base_chs * 4],
          out_channels=[base_chs * 2, base_chs * 8],
          num_heads=num_heads,
          drop_rate=drop_rate,
          drop_path_rate=drop_path_rate,
          use_injection=use_injection[0],
          use_cross_kv=True,
          cross_size=cross_size,
      )
      self.layer5 = EABlock(
          in_channels=[base_chs * 2, base_chs * 8],
          out_channels=[base_chs * 2, base_chs * 8],
          num_heads=num_heads,
          drop_rate=drop_rate,
          drop_path_rate=drop_path_rate,
          use_injection=use_injection[1],
          use_cross_kv=True,
          cross_size=cross_size,
      )
  
      self.spp = DAPPM(
          base_chs * 8, spp_channels, base_chs * 2, lr_mult=lr_mult
      )
      self.seghead = SegHead(
          base_chs * 4,
          int(head_channels * 2),
          num_classes,
          lr_mult=lr_mult,
      )
      self.use_aux_head = use_aux_head
      if self.use_aux_head:
          self.seghead_extra = SegHead(
              base_chs * 2, head_channels, num_classes, lr_mult=lr_mult
          )
  
      self.pretrained = pretrained
      self.init_weight()
  
imports: from functools import partial
  import paddle
  import paddle.nn
  import paddle.nn.functional
  from paddleseg.cvlibs import manager, param_init
  from paddleseg.models import layers
  from paddleseg.utils import utils
  from paddleseg.models.backbones.transformer_utils import DropPath, Identity
  from paddleseg.cvlibs.param_init import constant_init, kaiming_normal_init, trunc_normal_init
label_desc: Use image node_id 1 to create a new RTFormer object from inherited base classes: nn with example: obj = RTFormer(num_classes, layer_nums, base_channels, spp_channels, num_heads, head_channels, drop_rate, drop_path_rate, use_aux_head, use_injection, lr_mult, cross_size, in_channels, pretrained)