class_docstr: Video Swin Transformer.
  Ze Liu, Jia Ning, Yue Cao, Yixuan Wei, Zheng Zhang, Stephen Lin, Han Hu
  https://arxiv.org/pdf/2106.13230.pdf
  
  Args:
      pretrained (`str`):
          Load pretrained weights. Default: None
      pretrained2d (`bool`):
          Load image pretrained weights. Default: False
      patch_size (`tuple[int]`):
          Patch size. Default: (4,4,4).
      in_chans (`int)`:
          Number of input image channels. Default: 3.
      embed_dim (`int`):
          Number of linear projection output channels. Default: 96.
      depths (`tuple[int]`):
          Depths of each Swin Transformer stage.
      num_heads (`tuple[int]`):
          Number of attention head of each stage.
      window_size (`int`):
          Window size. Default: 7.
      mlp_ratio (`float`):
          Ratio of mlp hidden dim to embedding dim. Default: 4.
      num_classes (`int`):
          the classification num.
      qkv_bias (`bool`):
          If True, add a learnable bias to query, key, value. Default: True
      qk_scale (`float`):
          Override default qk scale of head_dim ** -0.5 if set.
      drop_rate (`float`):
          Dropout rate.
      attn_drop_rate (`float`):
          Attention dropout rate. Default: 0.
      drop_path_rate (`float`):
          Stochastic depth rate. Default: 0.2.
      norm_layer (`nn.Module`):
          Normalization layer. Default: nn.LayerNorm.
      patch_norm (`bool`):
          If True, add normalization after patch embedding. Default: False.
      frozen_stages (`int`):
          Stages to be frozen (stop grad and set eval mode).
          -1 means not freezing any parameters.
      use_checkpoint (`bool`):
          Use checkpoint.
      stride (`tuple[int]`):
          stride size for patch embed3d.
class_docstr_tok: ["Video","Swin","Transformer",".","Ze","Liu",",","Jia","Ning",",","Yue","Cao",",","Yixuan","Wei",",","Zheng","Zhang",",","Stephen","Lin",",","Han","Hu","https",":","\/\/arxiv.org\/pdf\/2106.13230.pdf","Args",":","pretrained","(","`","str","`",")",":","Load","pretrained","weights",".","Default",":","None","pretrained2d","(","`","bool","`",")",":","Load","image","pretrained","weights",".","Default",":","False","patch_size","(","`","tuple","[","int","]","`",")",":","Patch","size",".","Default",":","(","4,4,4",")",".","in_chans","(","`","int",")","`",":","Number","of","input","image","channels",".","Default",":","3.","embed_dim","(","`","int","`",")",":","Number","of","linear","projection","output","channels",".","Default",":","96.","depths","(","`","tuple","[","int","]","`",")",":","Depths","of","each","Swin","Transformer","stage",".","num_heads","(","`","tuple","[","int","]","`",")",":","Number","of","attention","head","of","each","stage",".","window_size","(","`","int","`",")",":","Window","size",".","Default",":","7.","mlp_ratio","(","`","float","`",")",":","Ratio","of","mlp","hidden","dim","to","embedding","dim",".","Default",":","4.","num_classes","(","`","int","`",")",":","the","classification","num",".","qkv_bias","(","`","bool","`",")",":","If","True",",","add","a","learnable","bias","to","query",",","key",",","value",".","Default",":","True","qk_scale","(","`","float","`",")",":","Override","default","qk","scale","of","head_dim","*","*","-0.5","if","set",".","drop_rate","(","`","float","`",")",":","Dropout","rate",".","attn_drop_rate","(","`","float","`",")",":","Attention","dropout","rate",".","Default",":","0.","drop_path_rate","(","`","float","`",")",":","Stochastic","depth","rate",".","Default",":","0.2.","norm_layer","(","`","nn.Module","`",")",":","Normalization","layer",".","Default",":","nn.LayerNorm",".","patch_norm","(","`","bool","`",")",":","If","True",",","add","normalization","after","patch","embedding",".","Default",":","False",".","frozen_stages","(","`","int","`",")",":","Stages","to","be","frozen","(","stop","grad","and","set","eval","mode",")",".","-1","means","not","freezing","any","parameters",".","use_checkpoint","(","`","bool","`",")",":","Use","checkpoint",".","stride","(","`","tuple","[","int","]","`",")",":","stride","size","for","patch","embed3d","."]
code: def __init__(
      self,
      pretrained=None,
      pretrained2d=False,
      patch_size=(4, 4, 4),
      in_chans=3,
      embed_dim=96,
      depths=(2, 2, 6, 2),
      num_heads=(3, 6, 12, 24),
      window_size=(2, 7, 7),
      mlp_ratio=4.0,
      num_classes=1000,
      qkv_bias=True,
      qk_scale=None,
      drop_rate=0.0,
      attn_drop_rate=0.0,
      drop_path_rate=0.2,
      cls_dropout_ratio=0.4,
      norm_layer=nn.LayerNorm,
      patch_norm=False,
      frozen_stages=-1,
      use_checkpoint=False,
      depth_mode=None,
      depth_patch_embed_separate_params=True,
      stride=None,
      device="cpu",
  ):
      super().__init__()
  
      self.pretrained = pretrained
      self.pretrained2d = pretrained2d
      self.num_layers = len(depths)
      self.embed_dim = embed_dim
      self.patch_norm = patch_norm
      self.frozen_stages = frozen_stages
      self.window_size = window_size
      self.patch_size = patch_size
      self.num_classes = num_classes
      # split image into non-overlapping patches
      self.patch_embed = PatchEmbed3D(
          patch_size=patch_size,
          c=in_chans,
          embed_dim=embed_dim,
          norm_layer=norm_layer if self.patch_norm else None,
          stride=stride,
      )
  
      if depth_mode is not None:
          assert depth_mode in [
              "separate_d_tokens",
              "summed_rgb_d_tokens",
              "rgbd",
          ]
          if depth_mode in ["separate_d_tokens", "summed_rgb_d_tokens"]:
              depth_chans = 1
              assert (
                  depth_patch_embed_separate_params
              ), "separate tokenization needs separate parameters"
              if depth_mode == "separate_d_tokens":
                  raise NotImplementedError()
          else:
              assert depth_mode == "rgbd"
              depth_chans = 4
  
          self.depth_patch_embed_separate_params = (
              depth_patch_embed_separate_params
          )
  
          if depth_patch_embed_separate_params:
              self.depth_patch_embed = PatchEmbed3D(
                  patch_size=patch_size,
                  c=depth_chans,
                  embed_dim=embed_dim,
                  norm_layer=norm_layer if self.patch_norm else None,
                  stride=stride,
              )
          else:
              # share parameters with patch_embed
              # delete the layer we built above
              del self.patch_embed
              assert depth_chans == 4
              self.patch_embed = PatchEmbed3D(
                  patch_size=patch_size,
                  c=3,
                  embed_dim=embed_dim,
                  additional_variable_channels=[1],
                  norm_layer=norm_layer if self.patch_norm else None,
                  stride=stride,
              )
  
      self.pos_drop = nn.Dropout(p=drop_rate)
  
      # stochastic depth
      dpr = [
          x.item()
          for x in torch.linspace(0, drop_path_rate, sum(depths))
      ]  # stochastic depth decay rule
  
      # build layers
      self.layers = nn.ModuleList()
      for i_layer in range(self.num_layers):
          layer = VideoSwinTransformerBlock(
              dim=int(embed_dim * 2**i_layer),
              depth=depths[i_layer],
              num_heads=num_heads[i_layer],
              window_size=window_size,
              mlp_ratio=mlp_ratio,
              qkv_bias=qkv_bias,
              qk_scale=qk_scale,
              drop=drop_rate,
              attn_drop=attn_drop_rate,
              drop_path=dpr[
                  sum(depths[:i_layer]) : sum(depths[: i_layer + 1])
              ],
              norm_layer=norm_layer,
              downsample=PatchMerging3D
              if i_layer < self.num_layers - 1
              else None,
              use_checkpoint=use_checkpoint,
          )
          self.layers.append(layer)
  
      self.num_features = int(embed_dim * 2 ** (self.num_layers - 1))
  
      # add a norm layer for each output
      self.norm = norm_layer(self.num_features)
      # use `nn.AdaptiveAvgPool3d` to adaptively match the in_channels.
      self.avg_pool3d = nn.AdaptiveAvgPool3d((1, 1, 1))
      self.cls_dropout_ratio = cls_dropout_ratio
      if self.cls_dropout_ratio != 0:
          self.dropout = nn.Dropout(p=self.cls_dropout_ratio)
      else:
          self.dropout = None
  
      self.fc_cls = nn.Linear(self.num_features, self.num_classes)
  
      self.apply(init_vit_weights)
      # if load pretrained weights
      if self.pretrained not in ["", None]:
          self.load_pretrained_weights(self.pretrained, device=device)
      self._freeze_stages()
  
imports: import torch
  from torch import nn
  from torch.utils import model_zoo
  from einops import rearrange
  from towhee.models.layers.patch_embed3d import PatchEmbed3D
  from towhee.models.layers.patch_merging3d import PatchMerging3D
  from towhee.models.video_swin_transformer.video_swin_transformer_block import VideoSwinTransformerBlock
  from towhee.models.video_swin_transformer import get_configs
  from towhee.models.utils.init_vit_weights import init_vit_weights
  from collections import OrderedDict
  import logging
label_desc: Use image node_id 1 to create a new VideoSwinTransformer object from inherited base classes: nn with example: obj = VideoSwinTransformer(pretrained, pretrained2d, patch_size, in_chans, embed_dim, depths, num_heads, window_size, mlp_ratio, num_classes, qkv_bias, qk_scale, drop_rate, attn_drop_rate, drop_path_rate, cls_dropout_ratio, norm_layer, patch_norm, frozen_stages, use_checkpoint, depth_mode, depth_patch_embed_separate_params, stride, device)