class_docstr: The SwinTransformer implementation based on PaddlePaddle.
  
  The original article refers to
  Liu, Ze, et al. "Swin Transformer: Hierarchical Vision Transformer using Shifted Windows"
  (https://arxiv.org/abs/2103.14030)
  
  Args:
      pretrain_img_size (int): Input image size for training the pretrained model, used in absolute postion embedding. Default: 224.
      patch_size (int | tuple(int)): Patch size. Default: 4.
      in_channels (int): Number of input image channels. Default: 3.
      embed_dim (int): Number of linear projection output channels. Default: 96.
      depths (tuple[int]): Depths of each Swin Transformer stage.
      num_heads (tuple[int]): Number of attention head of each stage.
      window_size (int): Window size. Default: 7.
      mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. Default: 4.
      qkv_bias (bool): If True, add a learnable bias to query, key, value. Default: True
      qk_scale (float): Override default qk scale of head_dim ** -0.5 if set.
      drop_rate (float): Dropout rate.
      attn_drop_rate (float): Attention dropout rate. Default: 0.
      drop_path_rate (float): Stochastic depth rate. Default: 0.2.
      norm_layer (nn.Layer): Normalization layer. Default: nn.LayerNorm.
      ape (bool): If True, add absolute position embedding to the patch embedding. Default: False.
      patch_norm (bool): If True, add normalization after patch embedding. Default: True.
      out_indices (Sequence[int]): Output from which stages.
      frozen_stages (int): Stages to be frozen (stop grad and set eval mode). -1 means not freezing any parameters. Default: -1.
      pretrained (str, optional): The path or url of pretrained model. Default: None.
class_docstr_tok: ["The","SwinTransformer","implementation","based","on","PaddlePaddle",".","The","original","article","refers","to","Liu",",","Ze",",","et","al",".","``","Swin","Transformer",":","Hierarchical","Vision","Transformer","using","Shifted","Windows","''","(","https",":","\/\/arxiv.org\/abs\/2103.14030",")","Args",":","pretrain_img_size","(","int",")",":","Input","image","size","for","training","the","pretrained","model",",","used","in","absolute","postion","embedding",".","Default",":","224.","patch_size","(","int","|","tuple","(","int",")",")",":","Patch","size",".","Default",":","4.","in_channels","(","int",")",":","Number","of","input","image","channels",".","Default",":","3.","embed_dim","(","int",")",":","Number","of","linear","projection","output","channels",".","Default",":","96.","depths","(","tuple","[","int","]",")",":","Depths","of","each","Swin","Transformer","stage",".","num_heads","(","tuple","[","int","]",")",":","Number","of","attention","head","of","each","stage",".","window_size","(","int",")",":","Window","size",".","Default",":","7.","mlp_ratio","(","float",")",":","Ratio","of","mlp","hidden","dim","to","embedding","dim",".","Default",":","4.","qkv_bias","(","bool",")",":","If","True",",","add","a","learnable","bias","to","query",",","key",",","value",".","Default",":","True","qk_scale","(","float",")",":","Override","default","qk","scale","of","head_dim","*","*","-0.5","if","set",".","drop_rate","(","float",")",":","Dropout","rate",".","attn_drop_rate","(","float",")",":","Attention","dropout","rate",".","Default",":","0.","drop_path_rate","(","float",")",":","Stochastic","depth","rate",".","Default",":","0.2.","norm_layer","(","nn.Layer",")",":","Normalization","layer",".","Default",":","nn.LayerNorm",".","ape","(","bool",")",":","If","True",",","add","absolute","position","embedding","to","the","patch","embedding",".","Default",":","False",".","patch_norm","(","bool",")",":","If","True",",","add","normalization","after","patch","embedding",".","Default",":","True",".","out_indices","(","Sequence","[","int","]",")",":","Output","from","which","stages",".","frozen_stages","(","int",")",":","Stages","to","be","frozen","(","stop","grad","and","set","eval","mode",")",".","-1","means","not","freezing","any","parameters",".","Default",":","-1.","pretrained","(","str",",","optional",")",":","The","path","or","url","of","pretrained","model",".","Default",":","None","."]
code: def __init__(
      self,
      pretrain_img_size=224,
      patch_size=4,
      in_channels=3,
      embed_dim=96,
      depths=[2, 2, 6, 2],
      num_heads=[3, 6, 12, 24],
      window_size=7,
      mlp_ratio=4.0,
      qkv_bias=True,
      qk_scale=None,
      drop_rate=0.0,
      attn_drop_rate=0.0,
      drop_path_rate=0.2,
      norm_layer=nn.LayerNorm,
      ape=False,
      patch_norm=True,
      out_indices=(0, 1, 2, 3),
      frozen_stages=-1,
      pretrained=None,
  ):
      super().__init__()
  
      self.pretrain_img_size = pretrain_img_size
      self.num_layers = len(depths)
      self.embed_dim = embed_dim
      self.ape = ape
      self.patch_norm = patch_norm
      self.out_indices = out_indices
      self.frozen_stages = frozen_stages
  
      # split image into non-overlapping patches
      self.patch_embed = PatchEmbed(
          patch_size=patch_size,
          in_chans=in_channels,
          embed_dim=embed_dim,
          norm_layer=norm_layer if self.patch_norm else None,
      )
  
      # absolute position embedding
      if self.ape:
          pretrain_img_size = to_2tuple(pretrain_img_size)
          patch_size = to_2tuple(patch_size)
          patches_resolution = [
              pretrain_img_size[0] // patch_size[0],
              pretrain_img_size[1] // patch_size[1],
          ]
  
          self.absolute_pos_embed = self.create_parameter(
              shape=(
                  1,
                  embed_dim,
                  patches_resolution[0],
                  patches_resolution[1],
              ),
              default_initializer=zeros_,
          )
          self.add_parameter(
              "absolute_pos_embed", self.absolute_pos_embed
          )
          trunc_normal_(self.absolute_pos_embed)
  
      self.pos_drop = nn.Dropout(p=drop_rate)
  
      # stochastic depth
      dpr = np.linspace(0, drop_path_rate, sum(depths)).tolist()
  
      # build layers
      self.layers = nn.LayerList()
      for i_layer in range(self.num_layers):
          layer = BasicLayer(
              dim=int(embed_dim * 2**i_layer),
              depth=depths[i_layer],
              num_heads=num_heads[i_layer],
              window_size=window_size,
              mlp_ratio=mlp_ratio,
              qkv_bias=qkv_bias,
              qk_scale=qk_scale,
              drop=drop_rate,
              attn_drop=attn_drop_rate,
              drop_path=dpr[
                  sum(depths[:i_layer]) : sum(depths[: i_layer + 1])
              ],
              norm_layer=norm_layer,
              downsample=PatchMerging
              if (i_layer < self.num_layers - 1)
              else None,
          )
          self.layers.append(layer)
  
      feat_channels = [
          int(embed_dim * 2**i) for i in range(self.num_layers)
      ]
      self.feat_channels = feat_channels
  
      # add a norm layer for each output
      for i_layer in out_indices:
          layer = norm_layer(feat_channels[i_layer])
          layer_name = f"norm{i_layer}"
          self.add_sublayer(layer_name, layer)
  
      self._freeze_stages()
  
      self.pretrained = pretrained
      self.init_weights(self.pretrained)
  
imports: import paddle
  import paddle.nn
  import paddle.nn.functional
  import numpy
  from paddleseg.cvlibs import manager
  from paddleseg.utils import utils
  from paddleseg.models.backbones.transformer_utils import *
label_desc: Use image node_id 1 to create a new SwinTransformer object from inherited base classes: nn with example: obj = SwinTransformer(pretrain_img_size, patch_size, in_channels, embed_dim, depths, num_heads, window_size, mlp_ratio, qkv_bias, qk_scale, drop_rate, attn_drop_rate, drop_path_rate, norm_layer, ape, patch_norm, out_indices, frozen_stages, pretrained)