class_docstr: Swin Transformer Block.
  Args:
      dim (int): Number of input channels.
      num_heads (int): Number of attention heads.
      window_size (List[int]): Window size.
      shift_size (List[int]): Shift size for shifted window attention.
      mlp_ratio (float): Ratio of mlp hidden dim to embedding dim. Default: 4.0.
      dropout (float): Dropout rate. Default: 0.0.
      attention_dropout (float): Attention dropout rate. Default: 0.0.
      stochastic_depth_prob: (float): Stochastic depth rate. Default: 0.0.
      norm_layer (nn.Module): Normalization layer.  Default: nn.LayerNorm.
      attn_layer (nn.Module): Attention layer. Default: ShiftedWindowAttention
class_docstr_tok: ["Swin","Transformer","Block",".","Args",":","dim","(","int",")",":","Number","of","input","channels",".","num_heads","(","int",")",":","Number","of","attention","heads",".","window_size","(","List","[","int","]",")",":","Window","size",".","shift_size","(","List","[","int","]",")",":","Shift","size","for","shifted","window","attention",".","mlp_ratio","(","float",")",":","Ratio","of","mlp","hidden","dim","to","embedding","dim",".","Default",":","4.0.","dropout","(","float",")",":","Dropout","rate",".","Default",":","0.0.","attention_dropout","(","float",")",":","Attention","dropout","rate",".","Default",":","0.0.","stochastic_depth_prob",":","(","float",")",":","Stochastic","depth","rate",".","Default",":","0.0.","norm_layer","(","nn.Module",")",":","Normalization","layer",".","Default",":","nn.LayerNorm",".","attn_layer","(","nn.Module",")",":","Attention","layer",".","Default",":","ShiftedWindowAttention"]
code: def __init__(
      self,
      opts,
      embed_dim: int,
      num_heads: int,
      window_size: List[int],
      shift_size: List[int],
      mlp_ratio: float = 4.0,
      dropout: float = 0.0,
      attn_dropout: Optional[float] = 0.0,
      ffn_dropout: Optional[float] = 0.0,
      stochastic_depth_prob: float = 0.0,
      norm_layer: Optional[str] = "layer_norm",
  ):
      super().__init__()
  
      attn_unit = ShiftedWindowAttention(
          embed_dim,
          window_size,
          shift_size,
          num_heads,
          attention_dropout=attn_dropout,
          dropout=dropout,
      )
      self.attn = nn.Sequential(
          get_normalization_layer(
              opts=opts, norm_type=norm_layer, num_features=embed_dim
          ),
          attn_unit,
          Dropout(p=dropout),
      )
  
      self.stochastic_depth = StochasticDepth(
          stochastic_depth_prob, "row"
      )
      ffn_latent_dim = int(embed_dim * mlp_ratio)
      act_name = build_activation_layer(opts, num_parameters=1)
      self.mlp = nn.Sequential(
          get_normalization_layer(
              opts=opts, norm_type=norm_layer, num_features=embed_dim
          ),
          LinearLayer(
              in_features=embed_dim,
              out_features=ffn_latent_dim,
              bias=True,
          ),
          act_name,
          Dropout(p=ffn_dropout),
          LinearLayer(
              in_features=ffn_latent_dim,
              out_features=embed_dim,
              bias=True,
          ),
          Dropout(p=dropout),
      )
      self.embed_dim = embed_dim
      self.ffn_dim = ffn_latent_dim
      self.ffn_dropout = ffn_dropout
      self.std_dropout = dropout
      self.attn_fn_name = attn_unit.__class__.__name__
      self.act_fn_name = act_name.__class__.__name__
      self.norm_type = norm_layer
  
imports: from typing import List, Optional
  import torch
  from torch import Tensor, nn
  from torch.nn import functional
  from cvnets.layers import Dropout, LinearLayer, StochasticDepth, get_normalization_layer
  from cvnets.layers.activation import build_activation_layer
  from cvnets.modules import BaseModule
label_desc: Use image node_id 1 to create a new SwinTransformerBlock object from inherited base classes: BaseModule with example: obj = SwinTransformerBlock(opts, embed_dim, num_heads, window_size, shift_size, mlp_ratio, dropout, attn_dropout, ffn_dropout, stochastic_depth_prob, norm_layer)