class_docstr: Swin Transformer
      A PaddlePaddle implementation of : `Swin Transformer: Hierarchical Vision Transformer using Shifted Windows`  -
        https://arxiv.org/pdf/2103.14030
  
  Args:
      img_size (int | tuple[int], optional): Input image size. Default 224
      patch_size (int | tuple[int], optional): Patch size. Default: 4
      in_chans (int, optional): Number of input image channels. Default: 3
      num_classes (int, optional): Number of classes for classification head. Default: 1000
      embed_dim (int, optional): Patch embedding dimension. Default: 96
      depths (tuple[int], optional): Depth of each Swin Transformer layer.
      num_heads (tuple[int], optional): Number of attention heads in different layers.
      window_size (int, optional): Window size. Default: 7
      mlp_ratio (float, optional): Ratio of mlp hidden dim to embedding dim. Default: 4
      qkv_bias (bool, optional): If True, add a learnable bias to query, key, value. Default: True
      qk_scale (float, optional): Override default query and key scale of head_dim ** -0.5 if set. Default: None
      drop_rate (float, optional): Dropout rate. Default: 0
      attn_drop_rate (float, optional): Attention dropout rate. Default: 0
      drop_path_rate (float, optional): Stochastic depth rate. Default: 0.1
      norm_layer (nn.Layer, optional): Normalization layer. Default: nn.LayerNorm.
      ape (bool, optional): If True, add absolute position embedding to the patch embedding. Default: False
      patch_norm (bool, optional): If True, add normalization after patch embedding. Default: True
class_docstr_tok: ["Swin","Transformer","A","PaddlePaddle","implementation","of",":","`","Swin","Transformer",":","Hierarchical","Vision","Transformer","using","Shifted","Windows","`","-","https",":","\/\/arxiv.org\/pdf\/2103.14030","Args",":","img_size","(","int","|","tuple","[","int","]",",","optional",")",":","Input","image","size",".","Default","224","patch_size","(","int","|","tuple","[","int","]",",","optional",")",":","Patch","size",".","Default",":","4","in_chans","(","int",",","optional",")",":","Number","of","input","image","channels",".","Default",":","3","num_classes","(","int",",","optional",")",":","Number","of","classes","for","classification","head",".","Default",":","1000","embed_dim","(","int",",","optional",")",":","Patch","embedding","dimension",".","Default",":","96","depths","(","tuple","[","int","]",",","optional",")",":","Depth","of","each","Swin","Transformer","layer",".","num_heads","(","tuple","[","int","]",",","optional",")",":","Number","of","attention","heads","in","different","layers",".","window_size","(","int",",","optional",")",":","Window","size",".","Default",":","7","mlp_ratio","(","float",",","optional",")",":","Ratio","of","mlp","hidden","dim","to","embedding","dim",".","Default",":","4","qkv_bias","(","bool",",","optional",")",":","If","True",",","add","a","learnable","bias","to","query",",","key",",","value",".","Default",":","True","qk_scale","(","float",",","optional",")",":","Override","default","query","and","key","scale","of","head_dim","*","*","-0.5","if","set",".","Default",":","None","drop_rate","(","float",",","optional",")",":","Dropout","rate",".","Default",":","0","attn_drop_rate","(","float",",","optional",")",":","Attention","dropout","rate",".","Default",":","0","drop_path_rate","(","float",",","optional",")",":","Stochastic","depth","rate",".","Default",":","0.1","norm_layer","(","nn.Layer",",","optional",")",":","Normalization","layer",".","Default",":","nn.LayerNorm",".","ape","(","bool",",","optional",")",":","If","True",",","add","absolute","position","embedding","to","the","patch","embedding",".","Default",":","False","patch_norm","(","bool",",","optional",")",":","If","True",",","add","normalization","after","patch","embedding",".","Default",":","True"]
code: def __init__(
      self,
      img_size=224,
      patch_size=4,
      in_chans=3,
      class_num=1000,
      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.1,
      norm_layer=nn.LayerNorm,
      ape=False,
      patch_norm=True,
      **kwargs,
  ):
      super(SwinTransformer, self).__init__()
  
      self.num_classes = num_classes = class_num
      self.num_layers = len(depths)
      self.embed_dim = embed_dim
      self.ape = ape
      self.patch_norm = patch_norm
      self.num_features = int(embed_dim * 2 ** (self.num_layers - 1))
      self.mlp_ratio = mlp_ratio
  
      # split image into non-overlapping patches
      self.patch_embed = PatchEmbed(
          img_size=img_size,
          patch_size=patch_size,
          in_chans=in_chans,
          embed_dim=embed_dim,
          norm_layer=norm_layer if self.patch_norm else None,
      )
      num_patches = self.patch_embed.num_patches
      patches_resolution = self.patch_embed.patches_resolution
      self.patches_resolution = patches_resolution
  
      # absolute position embedding
      if self.ape:
          self.absolute_pos_embed = self.create_parameter(
              shape=(1, num_patches, embed_dim),
              default_initializer=nn.initializer.Constant(value=0.0),
          )
          self.add_parameter(
              "absolute_pos_embed", self.absolute_pos_embed
          )
          param_init.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()  # stochastic depth decay rule
  
      # build layers
      self.layers = nn.LayerList()
      for i_layer in range(self.num_layers):
          layer = BasicLayer(
              dim=int(embed_dim * 2**i_layer),
              input_resolution=(
                  patches_resolution[0] // (2**i_layer),
                  patches_resolution[1] // (2**i_layer),
              ),
              depth=depths[i_layer],
              num_heads=num_heads[i_layer],
              window_size=window_size,
              mlp_ratio=self.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)
  
      self.norm = norm_layer(self.num_features)
      # self.avgpool = nn.AdaptiveAvgPool1D(1)
      # self.head = nn.Linear(
      # self.num_features,
      # num_classes) if self.num_classes > 0 else nn.Identity()
  
      self.init_weight()
  
imports: import numpy
  import paddle
  import paddle.nn
  from medicalseg.cvlibs import manager, param_init
  from medicalseg.utils import load_pretrained_model
  from medicalseg.models.backbones.transformer_utils import DropPath, to_2tuple
label_desc: Use image node_id 1 to create a new SwinTransformer object from inherited base classes: nn with example: obj = SwinTransformer(img_size, patch_size, in_chans, class_num, 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)