class_docstr: Swin Transformer based on: "Liu et al.,
  Swin Transformer: Hierarchical Vision Transformer using Shifted Windows
  <https://arxiv.org/abs/2103.14030>"
  https://github.com/microsoft/Swin-Transformer
docstr: Args:
      in_chans: dimension of input channels.
      embed_dim: number of linear projection output channels.
      window_size: local window size.
      patch_size: patch size.
      depths: number of layers in each stage.
      num_heads: number of attention heads.
      mlp_ratio: ratio of mlp hidden dim to embedding dim.
      qkv_bias: add a learnable bias to query, key, value.
      drop_rate: dropout rate.
      attn_drop_rate: attention dropout rate.
      drop_path_rate: stochastic depth rate.
      norm_layer: normalization layer.
      patch_norm: add normalization after patch embedding.
      use_checkpoint: use gradient checkpointing for reduced memory usage.
      spatial_dims: spatial dimension.
      downsample: module used for downsampling, available options are `"mergingv2"`, `"merging"` and a
          user-specified `nn.Module` following the API defined in :py:class:`monai.networks.nets.PatchMerging`.
          The default is currently `"merging"` (the original version defined in v0.9.0).
      use_v2: using swinunetr_v2, which adds a residual convolution block at the beginning of each swin stage.
docstr_tok: ["Args",":","in_chans",":","dimension","of","input","channels",".","embed_dim",":","number","of","linear","projection","output","channels",".","window_size",":","local","window","size",".","patch_size",":","patch","size",".","depths",":","number","of","layers","in","each","stage",".","num_heads",":","number","of","attention","heads",".","mlp_ratio",":","ratio","of","mlp","hidden","dim","to","embedding","dim",".","qkv_bias",":","add","a","learnable","bias","to","query",",","key",",","value",".","drop_rate",":","dropout","rate",".","attn_drop_rate",":","attention","dropout","rate",".","drop_path_rate",":","stochastic","depth","rate",".","norm_layer",":","normalization","layer",".","patch_norm",":","add","normalization","after","patch","embedding",".","use_checkpoint",":","use","gradient","checkpointing","for","reduced","memory","usage",".","spatial_dims",":","spatial","dimension",".","downsample",":","module","used","for","downsampling",",","available","options","are","`","``","mergingv2","''","`",",","`","``","merging","''","`","and","a","user-specified","`","nn.Module","`","following","the","API","defined","in",":","py",":","class",":","`","monai.networks.nets.PatchMerging","`",".","The","default","is","currently","`","``","merging","''","`","(","the","original","version","defined","in","v0.9.0",")",".","use_v2",":","using","swinunetr_v2",",","which","adds","a","residual","convolution","block","at","the","beginning","of","each","swin","stage","."]
code: def __init__(
      self,
      in_chans: int,
      embed_dim: int,
      window_size: Sequence[int],
      patch_size: Sequence[int],
      depths: Sequence[int],
      num_heads: Sequence[int],
      mlp_ratio: float = 4.0,
      qkv_bias: bool = True,
      drop_rate: float = 0.0,
      attn_drop_rate: float = 0.0,
      drop_path_rate: float = 0.0,
      norm_layer: type[LayerNorm] = nn.LayerNorm,
      patch_norm: bool = False,
      use_checkpoint: bool = False,
      spatial_dims: int = 3,
      downsample="merging",
      use_v2=False,
  ) -> None:
      """
      Args:
          in_chans: dimension of input channels.
          embed_dim: number of linear projection output channels.
          window_size: local window size.
          patch_size: patch size.
          depths: number of layers in each stage.
          num_heads: number of attention heads.
          mlp_ratio: ratio of mlp hidden dim to embedding dim.
          qkv_bias: add a learnable bias to query, key, value.
          drop_rate: dropout rate.
          attn_drop_rate: attention dropout rate.
          drop_path_rate: stochastic depth rate.
          norm_layer: normalization layer.
          patch_norm: add normalization after patch embedding.
          use_checkpoint: use gradient checkpointing for reduced memory usage.
          spatial_dims: spatial dimension.
          downsample: module used for downsampling, available options are `"mergingv2"`, `"merging"` and a
              user-specified `nn.Module` following the API defined in :py:class:`monai.networks.nets.PatchMerging`.
              The default is currently `"merging"` (the original version defined in v0.9.0).
          use_v2: using swinunetr_v2, which adds a residual convolution block at the beginning of each swin stage.
      """
  
      super().__init__()
      self.num_layers = len(depths)
      self.embed_dim = embed_dim
      self.patch_norm = patch_norm
      self.window_size = window_size
      self.patch_size = patch_size
      self.patch_embed = PatchEmbed(
          patch_size=self.patch_size,
          in_chans=in_chans,
          embed_dim=embed_dim,
          norm_layer=norm_layer if self.patch_norm else None,  # type: ignore
          spatial_dims=spatial_dims,
      )
      self.pos_drop = nn.Dropout(p=drop_rate)
      dpr = [
          x.item()
          for x in torch.linspace(0, drop_path_rate, sum(depths))
      ]
      self.use_v2 = use_v2
      self.layers1 = nn.ModuleList()
      self.layers2 = nn.ModuleList()
      self.layers3 = nn.ModuleList()
      self.layers4 = nn.ModuleList()
      if self.use_v2:
          self.layers1c = nn.ModuleList()
          self.layers2c = nn.ModuleList()
          self.layers3c = nn.ModuleList()
          self.layers4c = nn.ModuleList()
      down_sample_mod = (
          look_up_option(downsample, MERGING_MODE)
          if isinstance(downsample, str)
          else downsample
      )
      for i_layer in range(self.num_layers):
          layer = BasicLayer(
              dim=int(embed_dim * 2**i_layer),
              depth=depths[i_layer],
              num_heads=num_heads[i_layer],
              window_size=self.window_size,
              drop_path=dpr[
                  sum(depths[:i_layer]) : sum(depths[: i_layer + 1])
              ],
              mlp_ratio=mlp_ratio,
              qkv_bias=qkv_bias,
              drop=drop_rate,
              attn_drop=attn_drop_rate,
              norm_layer=norm_layer,
              downsample=down_sample_mod,
              use_checkpoint=use_checkpoint,
          )
          if i_layer == 0:
              self.layers1.append(layer)
          elif i_layer == 1:
              self.layers2.append(layer)
          elif i_layer == 2:
              self.layers3.append(layer)
          elif i_layer == 3:
              self.layers4.append(layer)
          if self.use_v2:
              layerc = UnetrBasicBlock(
                  spatial_dims=spatial_dims,
                  in_channels=embed_dim * 2**i_layer,
                  out_channels=embed_dim * 2**i_layer,
                  kernel_size=3,
                  stride=1,
                  norm_name="instance",
                  res_block=True,
              )
              if i_layer == 0:
                  self.layers1c.append(layerc)
              elif i_layer == 1:
                  self.layers2c.append(layerc)
              elif i_layer == 2:
                  self.layers3c.append(layerc)
              elif i_layer == 3:
                  self.layers4c.append(layerc)
  
      self.num_features = int(embed_dim * 2 ** (self.num_layers - 1))
  
imports: from __future__ import annotations
  import itertools
  from collections.abc import Sequence
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils.checkpoint
  from torch.nn import LayerNorm
  from typing_extensions import Final
  from monai.networks.blocks import MLPBlock
  from monai.networks.blocks import PatchEmbed, UnetOutBlock, UnetrBasicBlock, UnetrUpBlock
  from monai.networks.layers import DropPath, trunc_normal_
  from monai.utils import ensure_tuple_rep, look_up_option, optional_import
  from monai.utils.deprecate_utils import deprecated_arg
label_desc: Use image node_id 1 to create a new SwinTransformer object from inherited base classes: nn with example: obj = SwinTransformer(in_chans, embed_dim, window_size, patch_size, depths, num_heads, mlp_ratio, qkv_bias, drop_rate, attn_drop_rate, drop_path_rate, norm_layer, patch_norm, use_checkpoint, spatial_dims, downsample, use_v2)