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","."]
docstr: Inflate the swin2d parameters to swin3d.
  The differences between swin3d and swin2d mainly lie in an extra
  axis. To utilize the pretrained parameters in 2d model,
  the weight of swin2d models should be inflated to fit in the shapes of
  the 3d counterpart.
docstr_tok: ["Inflate","the","swin2d","parameters","to","swin3d",".","The","differences","between","swin3d","and","swin2d","mainly","lie","in","an","extra","axis",".","To","utilize","the","pretrained","parameters","in","2d","model",",","the","weight","of","swin2d","models","should","be","inflated","to","fit","in","the","shapes","of","the","3d","counterpart","."]
code: def inflate_weights(self):
      """
      Inflate the swin2d parameters to swin3d.
      The differences between swin3d and swin2d mainly lie in an extra
      axis. To utilize the pretrained parameters in 2d model,
      the weight of swin2d models should be inflated to fit in the shapes of
      the 3d counterpart.
  
      """
      checkpoint = torch.load(self.pretrained, map_location="cpu")
      state_dict = checkpoint["model"]
  
      # delete relative_position_index since we always re-init it
      relative_position_index_keys = [
          k for k in state_dict.keys() if "relative_position_index" in k
      ]
      for k in relative_position_index_keys:
          del state_dict[k]
  
      # delete attn_mask since we always re-init it
      attn_mask_keys = [
          k for k in state_dict.keys() if "attn_mask" in k
      ]
      for k in attn_mask_keys:
          del state_dict[k]
  
      state_dict["patch_embed.proj.weight"] = (
          state_dict["patch_embed.proj.weight"]
          .unsqueeze(2)
          .repeat(1, 1, self.patch_size[0], 1, 1)
          / self.patch_size[0]
      )
  
      # bicubic interpolate relative_position_bias_table if not match
      relative_position_bias_table_keys = [
          k
          for k in state_dict.keys()
          if "relative_position_bias_table" in k
      ]
      for k in relative_position_bias_table_keys:
          relative_position_bias_table_pretrained = state_dict[k]
          # pylint: disable=E1136
          relative_position_bias_table_current = self.state_dict()[k]
          l1, nh1 = relative_position_bias_table_pretrained.size()
          l2, nh2 = relative_position_bias_table_current.size()
          l2 = (2 * self.window_size[1] - 1) * (
              2 * self.window_size[2] - 1
          )
          wd = self.window_size[0]
          if nh1 != nh2:
              logging.info("Error in loading %s, passing", k)
          else:
              if l1 != l2:
                  s1 = int(l1**0.5)
                  relative_position_bias_table_pretrained_resized = torch.nn.functional.interpolate(
                      relative_position_bias_table_pretrained.permute(
                          1, 0
                      ).view(1, nh1, s1, s1),
                      size=(
                          2 * self.window_size[1] - 1,
                          2 * self.window_size[2] - 1,
                      ),
                      mode="bicubic",
                  )
                  relative_position_bias_table_pretrained = relative_position_bias_table_pretrained_resized.view(
                      nh2, l2
                  ).permute(
                      1, 0
                  )
          state_dict[
              k
          ] = relative_position_bias_table_pretrained.repeat(
              2 * wd - 1, 1
          )
  
      msg = self.load_state_dict(state_dict, strict=False)
      logging.info(msg)
      logging.info("=> loaded successfully %s", self.pretrained)
      del checkpoint
      torch.cuda.empty_cache()
  
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 3 for calling the VideoSwinTransformer obj's underlying member method code with example usage: obj.inflate_weights() without return types