class_docstr: ResNe(X)t 3D head.
  This layer performs a fully-connected projection during training, when the
  input size is 1x1x1. It performs a convolutional projection during testing
  when the input size is larger than 1x1x1. If the inputs are from multiple
  different pathways, the inputs will be concatenated after pooling.
class_docstr_tok: ["ResNe","(","X",")","t","3D","head",".","This","layer","performs","a","fully-connected","projection","during","training",",","when","the","input","size","is","1x1x1",".","It","performs","a","convolutional","projection","during","testing","when","the","input","size","is","larger","than","1x1x1",".","If","the","inputs","are","from","multiple","different","pathways",",","the","inputs","will","be","concatenated","after","pooling","."]
docstr: The `__init__` method of any subclass should also contain these
      arguments.
  ResNetBasicHead takes p pathways as input where p in [1, infty].
  
  Args:
      dim_in (list): the list of channel dimensions of the p inputs to the
          ResNetHead.
      num_classes (int): the channel dimensions of the p outputs to the
          ResNetHead.
      pool_size (list): the list of kernel sizes of p spatial temporal
          poolings, temporal pool kernel size, spatial pool kernel size,
          spatial pool kernel size in order.
      dropout_rate (float): dropout rate. If equal to 0.0, perform no
          dropout.
      act_func (string): activation function to use. 'softmax': applies
          softmax on the output. 'sigmoid': applies sigmoid on the output.
      detach_final_fc (bool): if True, detach the fc layer from the
          gradient graph. By doing so, only the final fc layer will be
          trained.
      cfg (struct): The config for the current experiment.
docstr_tok: ["The","`","__init__","`","method","of","any","subclass","should","also","contain","these","arguments",".","ResNetBasicHead","takes","p","pathways","as","input","where","p","in","[","1",",","infty","]",".","Args",":","dim_in","(","list",")",":","the","list","of","channel","dimensions","of","the","p","inputs","to","the","ResNetHead",".","num_classes","(","int",")",":","the","channel","dimensions","of","the","p","outputs","to","the","ResNetHead",".","pool_size","(","list",")",":","the","list","of","kernel","sizes","of","p","spatial","temporal","poolings",",","temporal","pool","kernel","size",",","spatial","pool","kernel","size",",","spatial","pool","kernel","size","in","order",".","dropout_rate","(","float",")",":","dropout","rate",".","If","equal","to","0.0",",","perform","no","dropout",".","act_func","(","string",")",":","activation","function","to","use",".","'softmax","'",":","applies","softmax","on","the","output",".","'sigmoid","'",":","applies","sigmoid","on","the","output",".","detach_final_fc","(","bool",")",":","if","True",",","detach","the","fc","layer","from","the","gradient","graph",".","By","doing","so",",","only","the","final","fc","layer","will","be","trained",".","cfg","(","struct",")",":","The","config","for","the","current","experiment","."]
code: def __init__(
      self,
      dim_in,
      num_classes,
      pool_size,
      dropout_rate=0.0,
      act_func="softmax",
      detach_final_fc=False,
      cfg=None,
  ):
      """
      The `__init__` method of any subclass should also contain these
          arguments.
      ResNetBasicHead takes p pathways as input where p in [1, infty].
  
      Args:
          dim_in (list): the list of channel dimensions of the p inputs to the
              ResNetHead.
          num_classes (int): the channel dimensions of the p outputs to the
              ResNetHead.
          pool_size (list): the list of kernel sizes of p spatial temporal
              poolings, temporal pool kernel size, spatial pool kernel size,
              spatial pool kernel size in order.
          dropout_rate (float): dropout rate. If equal to 0.0, perform no
              dropout.
          act_func (string): activation function to use. 'softmax': applies
              softmax on the output. 'sigmoid': applies sigmoid on the output.
          detach_final_fc (bool): if True, detach the fc layer from the
              gradient graph. By doing so, only the final fc layer will be
              trained.
          cfg (struct): The config for the current experiment.
      """
      super(ResNetBasicHead, self).__init__()
      assert (
          len({len(pool_size), len(dim_in)}) == 1
      ), "pathway dimensions are not consistent."
      self.num_pathways = len(pool_size)
      self.detach_final_fc = detach_final_fc
      self.cfg = cfg
      self.local_projection_modules = []
      self.predictors = nn.ModuleList()
      self.l2norm_feats = False
  
      for pathway in range(self.num_pathways):
          if pool_size[pathway] is None:
              avg_pool = nn.AdaptiveAvgPool3d((1, 1, 1))
          else:
              avg_pool = nn.AvgPool3d(pool_size[pathway], stride=1)
          self.add_module("pathway{}_avgpool".format(pathway), avg_pool)
  
      if dropout_rate > 0.0:
          self.dropout = nn.Dropout(dropout_rate)
      # Perform FC in a fully convolutional manner. The FC layer will be
      # initialized with a different std comparing to convolutional layers.
      if cfg.CONTRASTIVE.NUM_MLP_LAYERS == 1:
          self.projection = nn.Linear(
              sum(dim_in), num_classes, bias=True
          )
      else:
          self.projection = MLPHead(
              sum(dim_in),
              num_classes,
              cfg.CONTRASTIVE.MLP_DIM,
              cfg.CONTRASTIVE.NUM_MLP_LAYERS,
              bn_on=cfg.CONTRASTIVE.BN_MLP,
              bn_sync_num=cfg.BN.NUM_SYNC_DEVICES
              if cfg.CONTRASTIVE.BN_SYNC_MLP
              else 1,
              global_sync=(
                  cfg.CONTRASTIVE.BN_SYNC_MLP and cfg.BN.GLOBAL_SYNC
              ),
          )
  
      # Softmax for evaluation and testing.
      if act_func == "softmax":
          self.act = nn.Softmax(dim=4)
      elif act_func == "sigmoid":
          self.act = nn.Sigmoid()
      elif act_func == "none":
          self.act = None
      else:
          raise NotImplementedError(
              "{} is not supported as an activation"
              "function.".format(act_func)
          )
  
      if cfg.CONTRASTIVE.PREDICTOR_DEPTHS:
          d_in = num_classes
          for i, n_layers in enumerate(
              cfg.CONTRASTIVE.PREDICTOR_DEPTHS
          ):
              local_mlp = MLPHead(
                  d_in,
                  num_classes,
                  cfg.CONTRASTIVE.MLP_DIM,
                  n_layers,
                  bn_on=cfg.CONTRASTIVE.BN_MLP,
                  flatten=False,
                  bn_sync_num=cfg.BN.NUM_SYNC_DEVICES
                  if cfg.CONTRASTIVE.BN_SYNC_MLP
                  else 1,
                  global_sync=(
                      cfg.CONTRASTIVE.BN_SYNC_MLP and cfg.BN.GLOBAL_SYNC
                  ),
              )
              self.predictors.append(local_mlp)
  
imports: from functools import partial
  import torch
  import torch.nn
  from detectron2.layers import ROIAlign
  import slowfast.utils.logging
  from slowfast.models.attention import MultiScaleBlock
  from slowfast.models.batchnorm_helper import NaiveSyncBatchNorm1d
  from slowfast.models.nonlocal_helper import Nonlocal
label_desc: Use image node_id 1 to create a new ResNetBasicHead object from inherited base classes: nn with example: obj = ResNetBasicHead(dim_in, num_classes, pool_size, dropout_rate, act_func, detach_final_fc, cfg)