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: NOTE: this interface is experimental.
  
  Args:
      num_classes (int): number of foreground classes (i.e. background is not included)
      batch_size_per_image (int): number of proposals to sample for training
      positive_fraction (float): fraction of positive (foreground) proposals
          to sample for training.
      proposal_matcher (Matcher): matcher that matches proposals and ground truth
      proposal_append_gt (bool): whether to include ground truth as proposals as well
docstr_tok: ["NOTE",":","this","interface","is","experimental",".","Args",":","num_classes","(","int",")",":","number","of","foreground","classes","(","i.e",".","background","is","not","included",")","batch_size_per_image","(","int",")",":","number","of","proposals","to","sample","for","training","positive_fraction","(","float",")",":","fraction","of","positive","(","foreground",")","proposals","to","sample","for","training",".","proposal_matcher","(","Matcher",")",":","matcher","that","matches","proposals","and","ground","truth","proposal_append_gt","(","bool",")",":","whether","to","include","ground","truth","as","proposals","as","well"]
code: def __init__(
      self,
      *,
      num_classes,
      batch_size_per_image,
      positive_fraction,
      proposal_matcher,
      proposal_append_gt=True,
  ):
      """
      NOTE: this interface is experimental.
  
      Args:
          num_classes (int): number of foreground classes (i.e. background is not included)
          batch_size_per_image (int): number of proposals to sample for training
          positive_fraction (float): fraction of positive (foreground) proposals
              to sample for training.
          proposal_matcher (Matcher): matcher that matches proposals and ground truth
          proposal_append_gt (bool): whether to include ground truth as proposals as well
      """
      super().__init__()
      self.batch_size_per_image = batch_size_per_image
      self.positive_fraction = positive_fraction
      self.num_classes = num_classes
      self.proposal_matcher = proposal_matcher
      self.proposal_append_gt = proposal_append_gt
  
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 1 to create a new ROIHeads object from inherited base classes: torch.nn with example: obj = ROIHeads()