class_docstr: FrozenInTime model
  Args:
      img_size (`int`):
          The image or video height.
      patch_size (`int`):
          Patch height (equal to width).
      in_chans (`int`):
          Number of image channel.
      num_frames (`int`):
          Maximum number of frames expected as input.
      is_pretrained (`bool`):
          If true, then load the frozen pretrained model.
      weights_path (`str`):
          The frozen pretrained model path, if is_pretrained is true, and this not None, then load from this path,
          otherwise, will load the frozen model from an url.
      attention_style (`str`):
          Default is "frozen_in_time", if is "bridge_former", then is the BridgeFormer model.
      projection_dim (`int`):
          The output dim.
      video_pretrained_model (`str`):
          Default is "vit_base_16x224", if is_pretrained is false, then must load the pretrained vit parameters.
      video_is_load_pretrained (`bool`):
          If true, then will load vit pretrained weight.
      video_model_type (`str`) :
          Default is "SpaceTimeTransformer", the frozen model name, no need to change.
      text_pretrained_model (`str`):
          Default is "distilbert-base-uncased", the pretrained model for text encoder.
      text_is_load_pretrained (`bool`):
          If false, then will not load pretrained model for text encoder.
      projection (`str`):
          A layer.
      load_temporal_fix (`str`):
          If is_pretrained is true, this will use in function "_inflate_positional_embeds".
      device (`str`):
          "cpu" or "cuda".
      pretrained_url (`str`):
          If is_pretrained is true and weights_path is None, will load frozen pretrained model from this url.
class_docstr_tok: ["FrozenInTime","model","Args",":","img_size","(","`","int","`",")",":","The","image","or","video","height",".","patch_size","(","`","int","`",")",":","Patch","height","(","equal","to","width",")",".","in_chans","(","`","int","`",")",":","Number","of","image","channel",".","num_frames","(","`","int","`",")",":","Maximum","number","of","frames","expected","as","input",".","is_pretrained","(","`","bool","`",")",":","If","true",",","then","load","the","frozen","pretrained","model",".","weights_path","(","`","str","`",")",":","The","frozen","pretrained","model","path",",","if","is_pretrained","is","true",",","and","this","not","None",",","then","load","from","this","path",",","otherwise",",","will","load","the","frozen","model","from","an","url",".","attention_style","(","`","str","`",")",":","Default","is","``","frozen_in_time","''",",","if","is","``","bridge_former","''",",","then","is","the","BridgeFormer","model",".","projection_dim","(","`","int","`",")",":","The","output","dim",".","video_pretrained_model","(","`","str","`",")",":","Default","is","``","vit_base_16x224","''",",","if","is_pretrained","is","false",",","then","must","load","the","pretrained","vit","parameters",".","video_is_load_pretrained","(","`","bool","`",")",":","If","true",",","then","will","load","vit","pretrained","weight",".","video_model_type","(","`","str","`",")",":","Default","is","``","SpaceTimeTransformer","''",",","the","frozen","model","name",",","no","need","to","change",".","text_pretrained_model","(","`","str","`",")",":","Default","is","``","distilbert-base-uncased","''",",","the","pretrained","model","for","text","encoder",".","text_is_load_pretrained","(","`","bool","`",")",":","If","false",",","then","will","not","load","pretrained","model","for","text","encoder",".","projection","(","`","str","`",")",":","A","layer",".","load_temporal_fix","(","`","str","`",")",":","If","is_pretrained","is","true",",","this","will","use","in","function","``","_inflate_positional_embeds","''",".","device","(","`","str","`",")",":","``","cpu","''","or","``","cuda","''",".","pretrained_url","(","`","str","`",")",":","If","is_pretrained","is","true","and","weights_path","is","None",",","will","load","frozen","pretrained","model","from","this","url","."]
code: def _inflate_positional_embeds(self, new_state_dict):
      # allow loading of timesformer with fewer num_frames
      curr_keys = list(self.state_dict().keys())
      if (
          "video_model.temporal_embed" in new_state_dict
          and "video_model.temporal_embed" in curr_keys
      ):
          load_temporal_embed = new_state_dict[
              "video_model.temporal_embed"
          ]
          load_num_frames = load_temporal_embed.shape[1]
          curr_num_frames = self.num_frames
          embed_dim = load_temporal_embed.shape[2]
  
          if load_num_frames != curr_num_frames:
              if load_num_frames > curr_num_frames:
                  logging.info(
                      "### loaded %s model has MORE frames than current... "
                      "### loading weights, filling in the extras via %s",
                      self.video_model_type,
                      self.load_temporal_fix,
                  )
                  new_temporal_embed = load_temporal_embed[
                      :, :curr_num_frames, :
                  ]
              else:
                  logging.info(
                      "### loaded %s model has FEWER frames than current..."
                      "### loading weights, filling in the extras via %s",
                      self.video_model_type,
                      self.load_temporal_fix,
                  )
                  if self.load_temporal_fix == "zeros":
                      new_temporal_embed = torch.zeros(
                          [
                              load_temporal_embed.shape[0],
                              curr_num_frames,
                              embed_dim,
                          ]
                      )
                      new_temporal_embed[
                          :, :load_num_frames
                      ] = load_temporal_embed
                  elif self.load_temporal_fix in ["interp", "bilinear"]:
                      # interpolate
                      # unsqueeze so pytorch thinks its an image
                      mode = "nearest"
                      if self.load_temporal_fix == "bilinear":
                          mode = "bilinear"
                      load_temporal_embed = (
                          load_temporal_embed.unsqueeze(0)
                      )
                      new_temporal_embed = F.interpolate(
                          load_temporal_embed,
                          (curr_num_frames, embed_dim),
                          mode=mode,
                      ).squeeze(0)
                  else:
                      raise NotImplementedError
              new_state_dict[
                  "video_model.temporal_embed"
              ] = new_temporal_embed
      # allow loading with smaller spatial patches. assumes custom border crop, to append the
      # border patches to the input sequence
      if (
          "video_model.pos_embed" in new_state_dict
          and "video_model.pos_embed" in curr_keys
      ):
          load_pos_embed = new_state_dict["video_model.pos_embed"]
          load_num_patches = load_pos_embed.shape[1]
          curr_pos_embed = self.state_dict()["video_model.pos_embed"]
          if load_num_patches != curr_pos_embed.shape[1]:
              raise NotImplementedError(
                  "Loading models with different spatial resolution / patch number not yet implemented, sorry."
              )
  
      return new_state_dict
  
file_path: towhee/towhee/models/frozen_in_time/frozen_in_time.py
imports: import os
  import torch
  from torch import nn
  import torch.nn.functional
  from torch.utils import model_zoo
  from transformers import AutoModel, AutoConfig
  from towhee.models.frozen_in_time.frozen_video_transformer import SpaceTimeTransformer
  from towhee.models import vit
  from towhee.models.frozen_in_time.frozen_utils import sim_matrix, state_dict_data_parallel_fix, remove_bridge_module_state_dic
  import logging
label_desc: Use image node_id 5 for calling the FrozenInTime obj's underlying member method code with example usage: obj._inflate_positional_embeds(new_state_dict) and returns: new_state_dict