class_docstr: ResNe(X)t RoI head.
class_docstr_tok: ["ResNe","(","X",")","t","RoI","head","."]
docstr: The `__init__` method of any subclass should also contain these
      arguments.
  ResNetRoIHead 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.
      resolution (list): the list of spatial output size from the ROIAlign.
      scale_factor (list): the list of ratio to the input boxes by this
          number.
      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.
      aligned (bool): if False, use the legacy implementation. If True,
          align the results more perfectly.
      detach_final_fc (bool): if True, detach the final fc layer from the
          gradient graph. By doing so, only the final fc layer will be
          trained.
  Note:
      Given a continuous coordinate c, its two neighboring pixel indices
      (in our pixel model) are computed by floor (c - 0.5) and ceil
      (c - 0.5). For example, c=1.3 has pixel neighbors with discrete
      indices [0] and [1] (which are sampled from the underlying signal at
      continuous coordinates 0.5 and 1.5). But the original roi_align
      (aligned=False) does not subtract the 0.5 when computing neighboring
      pixel indices and therefore it uses pixels with a slightly incorrect
      alignment (relative to our pixel model) when performing bilinear
      interpolation.
      With `aligned=True`, we first appropriately scale the ROI and then
      shift it by -0.5 prior to calling roi_align. This produces the
      correct neighbors; It makes negligible differences to the model's
      performance if ROIAlign is used together with conv layers.
docstr_tok: ["The","`","__init__","`","method","of","any","subclass","should","also","contain","these","arguments",".","ResNetRoIHead","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",".","resolution","(","list",")",":","the","list","of","spatial","output","size","from","the","ROIAlign",".","scale_factor","(","list",")",":","the","list","of","ratio","to","the","input","boxes","by","this","number",".","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",".","aligned","(","bool",")",":","if","False",",","use","the","legacy","implementation",".","If","True",",","align","the","results","more","perfectly",".","detach_final_fc","(","bool",")",":","if","True",",","detach","the","final","fc","layer","from","the","gradient","graph",".","By","doing","so",",","only","the","final","fc","layer","will","be","trained",".","Note",":","Given","a","continuous","coordinate","c",",","its","two","neighboring","pixel","indices","(","in","our","pixel","model",")","are","computed","by","floor","(","c","-","0.5",")","and","ceil","(","c","-","0.5",")",".","For","example",",","c=1.3","has","pixel","neighbors","with","discrete","indices","[","0","]","and","[","1","]","(","which","are","sampled","from","the","underlying","signal","at","continuous","coordinates","0.5","and","1.5",")",".","But","the","original","roi_align","(","aligned=False",")","does","not","subtract","the","0.5","when","computing","neighboring","pixel","indices","and","therefore","it","uses","pixels","with","a","slightly","incorrect","alignment","(","relative","to","our","pixel","model",")","when","performing","bilinear","interpolation",".","With","`","aligned=True","`",",","we","first","appropriately","scale","the","ROI","and","then","shift","it","by","-0.5","prior","to","calling","roi_align",".","This","produces","the","correct","neighbors",";","It","makes","negligible","differences","to","the","model's","performance","if","ROIAlign","is","used","together","with","conv","layers","."]
code: def __init__(
      self,
      dim_in,
      num_classes,
      pool_size,
      resolution,
      scale_factor,
      dropout_rate=0.0,
      act_func="softmax",
      aligned=True,
      detach_final_fc=False,
  ):
      """
      The `__init__` method of any subclass should also contain these
          arguments.
      ResNetRoIHead 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.
          resolution (list): the list of spatial output size from the ROIAlign.
          scale_factor (list): the list of ratio to the input boxes by this
              number.
          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.
          aligned (bool): if False, use the legacy implementation. If True,
              align the results more perfectly.
          detach_final_fc (bool): if True, detach the final fc layer from the
              gradient graph. By doing so, only the final fc layer will be
              trained.
      Note:
          Given a continuous coordinate c, its two neighboring pixel indices
          (in our pixel model) are computed by floor (c - 0.5) and ceil
          (c - 0.5). For example, c=1.3 has pixel neighbors with discrete
          indices [0] and [1] (which are sampled from the underlying signal at
          continuous coordinates 0.5 and 1.5). But the original roi_align
          (aligned=False) does not subtract the 0.5 when computing neighboring
          pixel indices and therefore it uses pixels with a slightly incorrect
          alignment (relative to our pixel model) when performing bilinear
          interpolation.
          With `aligned=True`, we first appropriately scale the ROI and then
          shift it by -0.5 prior to calling roi_align. This produces the
          correct neighbors; It makes negligible differences to the model's
          performance if ROIAlign is used together with conv layers.
      """
      super(ResNetRoIHead, 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
  
      for pathway in range(self.num_pathways):
          temporal_pool = nn.AvgPool3d(
              [pool_size[pathway][0], 1, 1], stride=1
          )
          self.add_module("s{}_tpool".format(pathway), temporal_pool)
  
          roi_align = ROIAlign(
              resolution[pathway],
              spatial_scale=1.0 / scale_factor[pathway],
              sampling_ratio=0,
              aligned=aligned,
          )
          self.add_module("s{}_roi".format(pathway), roi_align)
          spatial_pool = nn.MaxPool2d(resolution[pathway], stride=1)
          self.add_module("s{}_spool".format(pathway), spatial_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.
      self.projection = nn.Linear(sum(dim_in), num_classes, bias=True)
  
      # Softmax for evaluation and testing.
      if act_func == "softmax":
          self.act = nn.Softmax(dim=1)
      elif act_func == "sigmoid":
          self.act = nn.Sigmoid()
      else:
          raise NotImplementedError(
              "{} is not supported as an activation"
              "function.".format(act_func)
          )
  
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 ResNetRoIHead object from inherited base classes: nn with example: obj = ResNetRoIHead(dim_in, num_classes, pool_size, resolution, scale_factor, dropout_rate, act_func, aligned, detach_final_fc)