class_docstr: Vision Transformer with support for patch or hybrid CNN input stage
class_docstr_tok: ["Vision","Transformer","with","support","for","patch","or","hybrid","CNN","input","stage"]
code: def get_intermediate_features(self, x, names):
      interms = []
  
      x = self.prepare_tokens(x)
  
      # get feature from every intermediate block and apply norm
      rel_pos_bias = (
          self.rel_pos_bias() if self.rel_pos_bias is not None else None
      )
      for blk in self.blocks:
          x = blk(x, rel_pos_bias=rel_pos_bias)
          interms.append(self.norm(x))
  
      # feature names are as follows
      # blkCLS[integer] => CLS token of blk[integer]
      # concatCLS[integer] => concat of CLS token from last #"integer" blocks
      # lastCLS => CLS token of last block
  
      output = []
      for name in names:
          if name.startswith("blkCLS"):
              v = int(name.replace("blkCLS", ""))
              output.append(interms[v][:, 0])
          elif name.startswith("concatCLS"):
              v = int(name.replace("concatCLS", ""))
              feat = torch.cat([x[:, 0] for x in interms[-v:]], dim=-1)
              output.append(feat)
          elif name == "lastCLS":
              output.append(interms[-1][:, 0])
      return output
  
imports: import copy
  import logging
  import math
  from functools import partial
  from typing import List
  import torch
  import torch.nn
  import torch.nn.functional
  from vissl.config import AttrDict
  from vissl.models.model_helpers import DropPath, to_2tuple, trunc_normal_
  from vissl.models.trunks import register_model_trunk
label_desc: Use image node_id 7 for calling the BEiT obj's underlying member method code with example usage: obj.get_intermediate_features(x, names) and returns: output