class_docstr: A basic Swin Transformer layer for one stage.
  
  Args:
      dim (int): Number of input channels.
      depth (int): Number of blocks.
      num_heads (int): Number of attention heads.
      window_size (int): Local window size.
      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 | tuple[float], optional): Stochastic depth rate. Default: 0.0
      downsample (layer.Layer | None, optional): Downsample layer at the end of the layer. Default: None
class_docstr_tok: ["A","basic","Swin","Transformer","layer","for","one","stage",".","Args",":","dim","(","int",")",":","Number","of","input","channels",".","depth","(","int",")",":","Number","of","blocks",".","num_heads","(","int",")",":","Number","of","attention","heads",".","window_size","(","int",")",":","Local","window","size",".","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","|","tuple","[","float","]",",","optional",")",":","Stochastic","depth","rate",".","Default",":","0.0","downsample","(","layer.Layer","|","None",",","optional",")",":","Downsample","layer","at","the","end","of","the","layer",".","Default",":","None"]
code: def __init__(
      self,
      dim,
      depth,
      num_heads,
      window_size,
      mlp_ratio=4.0,
      qkv_bias=True,
      drop=0.0,
      attn_drop=0.0,
      drop_path=0.0,
      downsample=None,
      name=None,
  ):
      super().__init__(name=name)
      self.dim = dim
      self.depth = depth
      self.window_size = window_size
      self.shift_size = window_size // 2
  
      # build blocks
      self.blocks = [
          SwinTransformerBlock(
              dim=dim,
              num_heads=num_heads,
              window_size=window_size,
              shift_size=0 if (i % 2 == 0) else self.shift_size,
              mlp_ratio=mlp_ratio,
              qkv_bias=qkv_bias,
              drop=drop,
              attn_drop=attn_drop,
              drop_path=drop_path[i]
              if isinstance(drop_path, list)
              else drop_path,
              name=f"block{i}",
          )
          for i in range(depth)
      ]
  
      # patch merging layer
      if downsample is not None:
          self.downsample = downsample(dim=dim, name="downsample")
      else:
          self.downsample = None
  
imports: import tensorflow
  from tensorflow.keras import Model, layers, initializers
  import numpy
label_desc: Use image node_id 1 to create a new BasicLayer object from inherited base classes: layers with example: obj = BasicLayer(dim, depth, num_heads, window_size, mlp_ratio, qkv_bias, drop, attn_drop, drop_path, downsample, name)