class_docstr: Swin Transformer Block.
  
  Args:
      dim (int): Number of input channels.
      num_heads (int): Number of attention heads.
      window_size (int): Window size.
      shift_size (int): Shift size for SW-MSA.
      mlp_ratio (float): Ratio of mlp hidden dim to embedding dim.
      qkv_bias (bool, optional): If True, add a learnable bias to query, key, value. Default: True
      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
class_docstr_tok: ["Swin","Transformer","Block",".","Args",":","dim","(","int",")",":","Number","of","input","channels",".","num_heads","(","int",")",":","Number","of","attention","heads",".","window_size","(","int",")",":","Window","size",".","shift_size","(","int",")",":","Shift","size","for","SW-MSA",".","mlp_ratio","(","float",")",":","Ratio","of","mlp","hidden","dim","to","embedding","dim",".","qkv_bias","(","bool",",","optional",")",":","If","True",",","add","a","learnable","bias","to","query",",","key",",","value",".","Default",":","True","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"]
code: def call(self, x, attn_mask, training=None):
      H, W = self.H, self.W
      B, L, C = x.shape
      assert L == H * W, "input feature has wrong size"
  
      shortcut = x
      x = self.norm1(x)
      x = tf.reshape(x, [B, H, W, C])
  
      # pad feature maps to multiples of window size
      # 把feature map给pad到window size的整数倍
      pad_r = (
          self.window_size - W % self.window_size
      ) % self.window_size
      pad_b = (
          self.window_size - H % self.window_size
      ) % self.window_size
      if pad_r > 0 or pad_b > 0:
          paddings = tf.constant(
              [[0, 0], [0, pad_r], [0, pad_b], [0, 0]]
          )
          x = tf.pad(x, paddings)
  
      _, Hp, Wp, _ = x.shape
  
      # cyclic shift
      if self.shift_size > 0:
          shifted_x = tf.roll(
              x, shift=(-self.shift_size, -self.shift_size), axis=(1, 2)
          )
      else:
          shifted_x = x
          attn_mask = None
  
      # partition windows
      x_windows = window_partition(
          shifted_x, self.window_size
      )  # [nW*B, Mh, Mw, C]
      x_windows = tf.reshape(
          x_windows, [-1, self.window_size * self.window_size, C]
      )  # [nW*B, Mh*Mw, C]
  
      # W-MSA/SW-MSA
      attn_windows = self.attn(
          x_windows, mask=attn_mask, training=training
      )  # [nW*B, Mh*Mw, C]
  
      # merge windows
      attn_windows = tf.reshape(
          attn_windows, [-1, self.window_size, self.window_size, C]
      )  # [nW*B, Mh, Mw, C]
      shifted_x = window_reverse(
          attn_windows, self.window_size, Hp, Wp
      )  # [B, H', W', C]
  
      # reverse cyclic shift
      if self.shift_size > 0:
          x = tf.roll(
              shifted_x,
              shift=(self.shift_size, self.shift_size),
              axis=(1, 2),
          )
      else:
          x = shifted_x
  
      if pad_r > 0 or pad_b > 0:
          # 把前面pad的数据移除掉
          x = tf.slice(x, begin=[0, 0, 0, 0], size=[B, H, W, C])
  
      x = tf.reshape(x, [B, H * W, C])
  
      # FFN
      x = shortcut + self.drop_path(x, training=training)
      x = x + self.drop_path(self.mlp(self.norm2(x)), training=training)
  
      return x
  
imports: import tensorflow
  from tensorflow.keras import Model, layers, initializers
  import numpy
label_desc: Use image node_id 2 for calling the SwinTransformerBlock obj's underlying member method code with example usage: obj.call(x, attn_mask, training) and returns: x