class_docstr: The ROIHeads in a typical "C4" R-CNN model, where
  the box and mask head share the cropping and
  the per-region feature computation by a Res5 block.
  See :paper:`ResNet` Appendix A.
class_docstr_tok: ["The","ROIHeads","in","a","typical","``","C4","''","R-CNN","model",",","where","the","box","and","mask","head","share","the","cropping","and","the","per-region","feature","computation","by","a","Res5","block",".","See",":","paper",":","`","ResNet","`","Appendix","A","."]
docstr: See :meth:`ROIHeads.forward`.
docstr_tok: ["See",":","meth",":","`","ROIHeads.forward","`","."]
code: def forward(
      self,
      images: ImageList,
      features: Dict[str, torch.Tensor],
      proposals: List[Instances],
      targets: Optional[List[Instances]] = None,
  ):
      """
      See :meth:`ROIHeads.forward`.
      """
      del images
  
      if self.training:
          assert targets
          proposals = self.label_and_sample_proposals(
              proposals, targets
          )
      del targets
  
      proposal_boxes = [x.proposal_boxes for x in proposals]
      box_features = self._shared_roi_transform(
          [features[f] for f in self.in_features], proposal_boxes
      )
      predictions = self.box_predictor(box_features.mean(dim=[2, 3]))
  
      if self.training:
          del features
          losses = self.box_predictor.losses(predictions, proposals)
          if self.mask_on:
              (
                  proposals,
                  fg_selection_masks,
              ) = select_foreground_proposals(
                  proposals, self.num_classes
              )
              # Since the ROI feature transform is shared between boxes and masks,
              # we don't need to recompute features. The mask loss is only defined
              # on foreground proposals, so we need to select out the foreground
              # features.
              mask_features = box_features[
                  torch.cat(fg_selection_masks, dim=0)
              ]
              del box_features
              losses.update(self.mask_head(mask_features, proposals))
          return [], losses
      else:
          pred_instances, _ = self.box_predictor.inference(
              predictions, proposals
          )
          pred_instances = self.forward_with_given_boxes(
              features, pred_instances
          )
          return pred_instances, {}
  
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 Res5ROIHeads obj's underlying member method code with example usage: obj.forward(images, features, proposals, targets) and returns: list,  losses, pred_instances,  dict