class_docstr: Vision Transformere
class_docstr_tok: ["Vision","Transformere"]
code: def forward_features(self, x):
      B = x.shape[0]
      x, T, W = self.patch_embed(x)
      cls_tokens = self.cls_token.expand(x.size(0), -1, -1)
      x = torch.cat((cls_tokens, x), dim=1)
  
      # resizing the positional embeddings in case they don't match the input at inference
      if x.size(1) != self.pos_embed.size(1):
          pos_embed = self.pos_embed
          cls_pos_embed = pos_embed[0, 0, :].unsqueeze(0).unsqueeze(1)
          other_pos_embed = (
              pos_embed[0, 1:, :].unsqueeze(0).transpose(1, 2)
          )
          P = int(other_pos_embed.size(2) ** 0.5)
          H = x.size(1) // W
          other_pos_embed = other_pos_embed.reshape(1, x.size(2), P, P)
          new_pos_embed = F.interpolate(
              other_pos_embed, size=(H, W), mode="nearest"
          )
          new_pos_embed = new_pos_embed.flatten(2)
          new_pos_embed = new_pos_embed.transpose(1, 2)
          new_pos_embed = torch.cat((cls_pos_embed, new_pos_embed), 1)
          x = x + new_pos_embed
      else:
          x = x + self.pos_embed
      x = self.pos_drop(x)
  
      # Time Embeddings
      if self.attention_type != "space_only":
          cls_tokens = x[:B, 0, :].unsqueeze(1)
          x = x[:, 1:]
          x = rearrange(x, "(b t) n m -> (b n) t m", b=B, t=T)
          # Resizing time embeddings in case they don't match
          if T != self.time_embed.size(1):
              time_embed = self.time_embed.transpose(1, 2)
              new_time_embed = F.interpolate(
                  time_embed, size=(T), mode="nearest"
              )
              new_time_embed = new_time_embed.transpose(1, 2)
              x = x + new_time_embed
          else:
              x = x + self.time_embed
          x = self.time_drop(x)
          x = rearrange(x, "(b n) t m -> b (n t) m", b=B, t=T)
          x = torch.cat((cls_tokens, x), dim=1)
  
      # Attention blocks
      for blk in self.blocks:
          x = blk(x, B, T, W)
  
      # Predictions for space-only baseline
      if self.attention_type == "space_only":
          x = rearrange(x, "(b t) n m -> b t n m", b=B, t=T)
          x = torch.mean(x, 1)  # averaging predictions for every frame
  
      x = self.norm(x)
  
      return x
  
imports: import logging
  from functools import partial
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.utils
  import torch.utils.checkpoint
  from einops import rearrange
  from fairscale.nn.checkpoint.checkpoint_activations import checkpoint_wrapper
  from .helpers import load_pretrained, load_pretrained_imagenet, load_pretrained_kinetics
  from .vit_utils import IMAGENET_DEFAULT_MEAN, IMAGENET_DEFAULT_STD, DropPath, to_2tuple, trunc_normal_
label_desc: Use image node_id 7 for calling the VisionTransformer obj's underlying member method code with example usage: obj.forward_features(x) and returns: x