class_docstr: Vision transformer with locally-initializable self-attention layers
class_docstr_tok: ["Vision","transformer","with","locally-initializable","self-attention","layers"]
code: def forward_features(self, x):
      B = x.shape[0]
      x = self.patch_embed(x)
  
      # stole class_tokens impl from Phil Wang, thanks
      class_tokens = self.class_token.expand(B, -1, -1)
  
      pos_embedding = self.interpolate_pos_embedding_to_data(
          x, self.pos_embedding
      )
      x = x + pos_embedding
      x = self.pos_drop(x)
  
      if self.class_token_in_local_layers:
          x = torch.cat((class_tokens, x), dim=1)
      for u, blk in enumerate(self.blocks):
          if (
              u == self.n_gpsa_layers
              and not self.class_token_in_local_layers
          ):
              x = torch.cat((class_tokens, x), dim=1)
          x = blk(x)
  
      x = self.norm(x)
  
      if self.classifier == "token":
          # just return the output for the class token
          x = x[:, 0, :]
      else:
          x = x.mean(dim=1)
      return x
  
imports: import copy
  import logging
  import math
  import torch
  import torch.nn
  from vissl.models.model_helpers import DropPath, to_2tuple, trunc_normal_
  from vissl.models.trunks import register_model_trunk
  from vissl.utils.hydra_config import AttrDict
label_desc: Use image node_id 4 for calling the ConViT obj's underlying member method code with example usage: obj.forward_features(x) and returns: x