class_docstr: ROIHeads perform all per-region computation in an R-CNN.
  
  It typically contains logic to
  
  1. (in training only) match proposals with ground truth and sample them
  2. crop the regions and extract per-region features using proposals
  3. make per-region predictions with different heads
  
  It can have many variants, implemented as subclasses of this class.
  This base class contains the logic to match/sample proposals.
  But it is not necessary to inherit this class if the sampling logic is not needed.
class_docstr_tok: ["ROIHeads","perform","all","per-region","computation","in","an","R-CNN",".","It","typically","contains","logic","to","1",".","(","in","training","only",")","match","proposals","with","ground","truth","and","sample","them","2.","crop","the","regions","and","extract","per-region","features","using","proposals","3.","make","per-region","predictions","with","different","heads","It","can","have","many","variants",",","implemented","as","subclasses","of","this","class",".","This","base","class","contains","the","logic","to","match\/sample","proposals",".","But","it","is","not","necessary","to","inherit","this","class","if","the","sampling","logic","is","not","needed","."]
docstr: Args:
      images (ImageList):
      features (dict[str,Tensor]): input data as a mapping from feature
          map name to tensor. Axis 0 represents the number of images `N` in
          the input data; axes 1-3 are channels, height, and width, which may
          vary between feature maps (e.g., if a feature pyramid is used).
      proposals (list[Instances]): length `N` list of `Instances`. The i-th
          `Instances` contains object proposals for the i-th input image,
          with fields "proposal_boxes" and "objectness_logits".
      targets (list[Instances], optional): length `N` list of `Instances`. The i-th
          `Instances` contains the ground-truth per-instance annotations
          for the i-th input image.  Specify `targets` during training only.
          It may have the following fields:
  
          - gt_boxes: the bounding box of each instance.
          - gt_classes: the label for each instance with a category ranging in [0, #class].
          - gt_masks: PolygonMasks or BitMasks, the ground-truth masks of each instance.
          - gt_keypoints: NxKx3, the groud-truth keypoints for each instance.
  
  Returns:
      list[Instances]: length `N` list of `Instances` containing the
      detected instances. Returned during inference only; may be [] during training.
  
      dict[str->Tensor]:
      mapping from a named loss to a tensor storing the loss. Used during training only.
docstr_tok: ["Args",":","images","(","ImageList",")",":","features","(","dict","[","str",",","Tensor","]",")",":","input","data","as","a","mapping","from","feature","map","name","to","tensor",".","Axis","0","represents","the","number","of","images","`","N","`","in","the","input","data",";","axes","1-3","are","channels",",","height",",","and","width",",","which","may","vary","between","feature","maps","(","e.g.",",","if","a","feature","pyramid","is","used",")",".","proposals","(","list","[","Instances","]",")",":","length","`","N","`","list","of","`","Instances","`",".","The","i-th","`","Instances","`","contains","object","proposals","for","the","i-th","input","image",",","with","fields","``","proposal_boxes","''","and","``","objectness_logits","''",".","targets","(","list","[","Instances","]",",","optional",")",":","length","`","N","`","list","of","`","Instances","`",".","The","i-th","`","Instances","`","contains","the","ground-truth","per-instance","annotations","for","the","i-th","input","image",".","Specify","`","targets","`","during","training","only",".","It","may","have","the","following","fields",":","-","gt_boxes",":","the","bounding","box","of","each","instance",".","-","gt_classes",":","the","label","for","each","instance","with","a","category","ranging","in","[","0",",","#","class","]",".","-","gt_masks",":","PolygonMasks","or","BitMasks",",","the","ground-truth","masks","of","each","instance",".","-","gt_keypoints",":","NxKx3",",","the","groud-truth","keypoints","for","each","instance",".","Returns",":","list","[","Instances","]",":","length","`","N","`","list","of","`","Instances","`","containing","the","detected","instances",".","Returned","during","inference","only",";","may","be","[","]","during","training",".","dict","[","str-",">","Tensor","]",":","mapping","from","a","named","loss","to","a","tensor","storing","the","loss",".","Used","during","training","only","."]
code: def forward(
      self,
      images: ImageList,
      features: Dict[str, torch.Tensor],
      proposals: List[Instances],
      targets: Optional[List[Instances]] = None,
  ) -> Tuple[List[Instances], Dict[str, torch.Tensor]]:
      """
      Args:
          images (ImageList):
          features (dict[str,Tensor]): input data as a mapping from feature
              map name to tensor. Axis 0 represents the number of images `N` in
              the input data; axes 1-3 are channels, height, and width, which may
              vary between feature maps (e.g., if a feature pyramid is used).
          proposals (list[Instances]): length `N` list of `Instances`. The i-th
              `Instances` contains object proposals for the i-th input image,
              with fields "proposal_boxes" and "objectness_logits".
          targets (list[Instances], optional): length `N` list of `Instances`. The i-th
              `Instances` contains the ground-truth per-instance annotations
              for the i-th input image.  Specify `targets` during training only.
              It may have the following fields:
  
              - gt_boxes: the bounding box of each instance.
              - gt_classes: the label for each instance with a category ranging in [0, #class].
              - gt_masks: PolygonMasks or BitMasks, the ground-truth masks of each instance.
              - gt_keypoints: NxKx3, the groud-truth keypoints for each instance.
  
      Returns:
          list[Instances]: length `N` list of `Instances` containing the
          detected instances. Returned during inference only; may be [] during training.
  
          dict[str->Tensor]:
          mapping from a named loss to a tensor storing the loss. Used during training only.
      """
      raise NotImplementedError()
  
imports: import inspect
  import logging
  import numpy
  from typing import Dict, List, Optional, Tuple
  import torch
  from torch import nn
  from detectron2.config import configurable
  from detectron2.layers import ShapeSpec, nonzero_tuple
  from detectron2.structures import Boxes, ImageList, Instances, pairwise_iou
  from detectron2.utils.events import get_event_storage
  from detectron2.utils.registry import Registry
  from ..backbone.resnet import BottleneckBlock, ResNet
  from ..matcher import Matcher
  from ..poolers import ROIPooler
  from ..proposal_generator.proposal_utils import add_ground_truth_to_proposals
  from ..sampling import subsample_labels
  from .box_head import build_box_head
  from .fast_rcnn import FastRCNNOutputLayers
  from .keypoint_head import build_keypoint_head
  from .mask_head import build_mask_head
label_desc: Use image node_id 5 for calling the ROIHeads obj's underlying member method code with example usage: obj.forward(images, features, proposals, targets) without return types