class_docstr: Swin Transformer Block.
  Args:
      dim (int): Number of input channels.
      input_resolution (tuple[int]): Input resulotion.
      num_heads (int): Number of attention heads.
      window_size (int, optional): Window size. Default: 7
      shift_size (int, optional): Shift size for SW-MSA.
      mlp_ratio (float, optional): Ratio of mlp hidden dim to embedding dim.
      qkv_bias (bool, optional): If True, add a learnable bias to query, key, value. Default: True
      qk_scale (float | None, optional): Override default query and key scale of head_dim ** -0.5 if set.
      drop (float, optional): Dropout rate. Default: 0.0
      attn_drop (float, optional): Attention dropout rate. Default: 0.0
      drop_path (float, optional): Stochastic depth rate. Default: 0.0
      act_layer (nn.Layer, optional): Activation layer. Default: nn.GELU
      norm_layer (nn.Layer, optional): Normalization layer.  Default: nn.LayerNorm
class_docstr_tok: ["Swin","Transformer","Block",".","Args",":","dim","(","int",")",":","Number","of","input","channels",".","input_resolution","(","tuple","[","int","]",")",":","Input","resulotion",".","num_heads","(","int",")",":","Number","of","attention","heads",".","window_size","(","int",",","optional",")",":","Window","size",".","Default",":","7","shift_size","(","int",",","optional",")",":","Shift","size","for","SW-MSA",".","mlp_ratio","(","float",",","optional",")",":","Ratio","of","mlp","hidden","dim","to","embedding","dim",".","qkv_bias","(","bool",",","optional",")",":","If","True",",","add","a","learnable","bias","to","query",",","key",",","value",".","Default",":","True","qk_scale","(","float","|","None",",","optional",")",":","Override","default","query","and","key","scale","of","head_dim","*","*","-0.5","if","set",".","drop","(","float",",","optional",")",":","Dropout","rate",".","Default",":","0.0","attn_drop","(","float",",","optional",")",":","Attention","dropout","rate",".","Default",":","0.0","drop_path","(","float",",","optional",")",":","Stochastic","depth","rate",".","Default",":","0.0","act_layer","(","nn.Layer",",","optional",")",":","Activation","layer",".","Default",":","nn.GELU","norm_layer","(","nn.Layer",",","optional",")",":","Normalization","layer",".","Default",":","nn.LayerNorm"]
code: def __init__(
      self,
      dim,
      input_resolution,
      num_heads,
      window_size=7,
      shift_size=0,
      mlp_ratio=4.0,
      qkv_bias=True,
      qk_scale=None,
      drop=0.0,
      attn_drop=0.0,
      drop_path=0.0,
      act_layer=nn.GELU,
      norm_layer=nn.LayerNorm,
  ):
      super().__init__()
      self.dim = dim
      self.input_resolution = input_resolution
      self.num_heads = num_heads
      self.window_size = window_size
      self.shift_size = shift_size
      self.mlp_ratio = mlp_ratio
      if min(self.input_resolution) <= self.window_size:
          # if window size is larger than input resolution, we don't partition windows
          self.shift_size = 0
          self.window_size = min(self.input_resolution)
      assert (
          0 <= self.shift_size < self.window_size
      ), "shift_size must be in 0-window_size"
  
      self.norm1 = norm_layer(dim)
      self.attn = WindowAttention(
          dim,
          window_size=to_2tuple(self.window_size),
          num_heads=num_heads,
          qkv_bias=qkv_bias,
          qk_scale=qk_scale,
          attn_drop=attn_drop,
          proj_drop=drop,
      )
  
      self.drop_path = (
          DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
      )
      self.norm2 = norm_layer(dim)
      mlp_hidden_dim = int(dim * mlp_ratio)
      self.mlp = Mlp(
          in_features=dim,
          hidden_features=mlp_hidden_dim,
          act_layer=act_layer,
          drop=drop,
      )
  
      if self.shift_size > 0:
          # calculate attention mask for SW-MSA
          H, W = self.input_resolution
          img_mask = paddle.zeros((1, H, W, 1))  # 1 H W 1
          h_slices = (
              slice(0, -self.window_size),
              slice(-self.window_size, -self.shift_size),
              slice(-self.shift_size, None),
          )
          w_slices = (
              slice(0, -self.window_size),
              slice(-self.window_size, -self.shift_size),
              slice(-self.shift_size, None),
          )
          cnt = 0
          for h in h_slices:
              for w in w_slices:
                  img_mask[:, h, w, :] = cnt
                  cnt += 1
  
          mask_windows = window_partition(
              img_mask, self.window_size
          )  # nW, window_size, window_size, 1
          mask_windows = mask_windows.reshape(
              [-1, self.window_size * self.window_size]
          )
          attn_mask = mask_windows.unsqueeze(
              1
          ) - mask_windows.unsqueeze(2)
  
          huns = -100.0 * paddle.ones_like(attn_mask)
          attn_mask = huns * (attn_mask != 0).astype("float32")
      else:
          attn_mask = None
  
      self.register_buffer("attn_mask", attn_mask)
  
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 SwinTransformerBlock object from inherited base classes: nn with example: obj = SwinTransformerBlock(dim, input_resolution, num_heads, window_size, shift_size, mlp_ratio, qkv_bias, qk_scale, drop, attn_drop, drop_path, act_layer, norm_layer)