class_docstr: A basic Swin Transformer layer for one stage.
  
  Args:
      dim (int): Number of feature channels
      depth (int): Depths of this stage.
      num_heads (int): Number of attention head.
      window_size (int): Local window size. Default: 7.
      mlp_ratio (float): 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 | None, optional): Override default qk 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 | tuple[float], optional): Stochastic depth rate. Default: 0.0
      norm_layer (nn.Module, optional): Normalization layer. Default: nn.LayerNorm
      downsample (nn.Module | None, optional): Downsample layer at the end of the layer. Default: None
      use_checkpoint (bool): Whether to use checkpointing to save memory. Default: False.
class_docstr_tok: ["A","basic","Swin","Transformer","layer","for","one","stage",".","Args",":","dim","(","int",")",":","Number","of","feature","channels","depth","(","int",")",":","Depths","of","this","stage",".","num_heads","(","int",")",":","Number","of","attention","head",".","window_size","(","int",")",":","Local","window","size",".","Default",":","7.","mlp_ratio","(","float",")",":","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","|","None",",","optional",")",":","Override","default","qk","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","|","tuple","[","float","]",",","optional",")",":","Stochastic","depth","rate",".","Default",":","0.0","norm_layer","(","nn.Module",",","optional",")",":","Normalization","layer",".","Default",":","nn.LayerNorm","downsample","(","nn.Module","|","None",",","optional",")",":","Downsample","layer","at","the","end","of","the","layer",".","Default",":","None","use_checkpoint","(","bool",")",":","Whether","to","use","checkpointing","to","save","memory",".","Default",":","False","."]
code: def __init__(
      self,
      dim,
      depth,
      num_heads,
      window_size=7,
      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,
      downsample=None,
      use_checkpoint=False,
  ):
      super().__init__()
      self.window_size = window_size
      self.shift_size = window_size // 2
      self.depth = depth
      self.use_checkpoint = use_checkpoint
  
      # build blocks
      self.blocks = nn.ModuleList(
          [
              SwinTransformerBlock(
                  dim=dim,
                  num_heads=num_heads,
                  window_size=window_size,
                  shift_size=0 if (i % 2 == 0) else window_size // 2,
                  mlp_ratio=mlp_ratio,
                  qkv_bias=qkv_bias,
                  qk_scale=qk_scale,
                  drop=drop,
                  attn_drop=attn_drop,
                  drop_path=drop_path[i]
                  if isinstance(drop_path, list)
                  else drop_path,
                  act_layer=act_layer,
                  norm_layer=norm_layer,
              )
              for i in range(depth)
          ]
      )
  
      # patch merging layer
      if downsample is not None:
          self.downsample = downsample(dim=dim, norm_layer=norm_layer)
      else:
          self.downsample = None
  
imports: from collections import OrderedDict
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils.checkpoint
  from torch import Tensor
  from .common import EncoderModule, _take, make_n_channel_input
  from ..activations import get_activation_block, ACT_GELU
  from timm.models.layers import DropPath, to_2tuple, trunc_normal_
label_desc: Use image node_id 1 to create a new BasicLayer object from inherited base classes: nn with example: obj = BasicLayer(dim, depth, num_heads, window_size, mlp_ratio, qkv_bias, qk_scale, drop, attn_drop, drop_path, act_layer, norm_layer, downsample, use_checkpoint)