class_docstr: A [Faster R-CNN](https://arxiv.org/abs/1506.01497) pretrained region detector.
  
  Unless you really know what you're doing, this should be used with the image
  features created from the `ResnetBackbone` `GridEmbedder` and on images loaded
  using the `TorchImageLoader` with the default settings.
  
  
  !!! Note
      This module does not have any trainable parameters by default.
      All pretrained weights are frozen.
  
  # Parameters
  
  box_score_thresh : `float`, optional (default = `0.05`)
      During inference, only proposal boxes / regions with a label classification score
      greater than `box_score_thresh` will be returned.
  
  box_nms_thresh : `float`, optional (default = `0.5`)
      During inference, non-maximum suppression (NMS) will applied to groups of boxes
      that share a common label.
  
      NMS iteratively removes lower scoring boxes which have an intersection-over-union (IoU)
      greater than `box_nms_thresh` with another higher scoring box.
  
  max_boxes_per_image : `int`, optional (default = `100`)
      During inference, at most `max_boxes_per_image` boxes will be returned. The
      number of boxes returned will vary by image and will often be lower
      than `max_boxes_per_image` depending on the values of `box_score_thresh`
      and `box_nms_thresh`.
class_docstr_tok: ["A","[","Faster","R-CNN","]","(","https",":","\/\/arxiv.org\/abs\/1506.01497",")","pretrained","region","detector",".","Unless","you","really","know","what","you","'re","doing",",","this","should","be","used","with","the","image","features","created","from","the","`","ResnetBackbone","`","`","GridEmbedder","`","and","on","images","loaded","using","the","`","TorchImageLoader","`","with","the","default","settings",".","!","!","!","Note","This","module","does","not","have","any","trainable","parameters","by","default",".","All","pretrained","weights","are","frozen",".","#","Parameters","box_score_thresh",":","`","float","`",",","optional","(","default","=","`","0.05","`",")","During","inference",",","only","proposal","boxes","\/","regions","with","a","label","classification","score","greater","than","`","box_score_thresh","`","will","be","returned",".","box_nms_thresh",":","`","float","`",",","optional","(","default","=","`","0.5","`",")","During","inference",",","non-maximum","suppression","(","NMS",")","will","applied","to","groups","of","boxes","that","share","a","common","label",".","NMS","iteratively","removes","lower","scoring","boxes","which","have","an","intersection-over-union","(","IoU",")","greater","than","`","box_nms_thresh","`","with","another","higher","scoring","box",".","max_boxes_per_image",":","`","int","`",",","optional","(","default","=","`","100","`",")","During","inference",",","at","most","`","max_boxes_per_image","`","boxes","will","be","returned",".","The","number","of","boxes","returned","will","vary","by","image","and","will","often","be","lower","than","`","max_boxes_per_image","`","depending","on","the","values","of","`","box_score_thresh","`","and","`","box_nms_thresh","`","."]
docstr: Extract regions and region features from the given images.
  
  In most cases `image_features` should come directly from the `ResnetBackbone`
  `GridEmbedder`. The `images` themselves should be standardized and resized
  using the default settings for the `TorchImageLoader`.
docstr_tok: ["Extract","regions","and","region","features","from","the","given","images",".","In","most","cases","`","image_features","`","should","come","directly","from","the","`","ResnetBackbone","`","`","GridEmbedder","`",".","The","`","images","`","themselves","should","be","standardized","and","resized","using","the","default","settings","for","the","`","TorchImageLoader","`","."]
code: def forward(
      self,
      images: FloatTensor,
      sizes: IntTensor,
      image_features: "OrderedDict[str, FloatTensor]",
  ) -> RegionDetectorOutput:
      """
      Extract regions and region features from the given images.
  
      In most cases `image_features` should come directly from the `ResnetBackbone`
      `GridEmbedder`. The `images` themselves should be standardized and resized
      using the default settings for the `TorchImageLoader`.
      """
      if self.training:
          raise RuntimeError(
              "FasterRcnnRegionDetector can not be used for training at the moment"
          )
  
      # Adapted from https://github.com/pytorch/vision/blob/
      # 4521f6d152875974e317fa247a633e9ad1ea05c8/torchvision/models/detection/generalized_rcnn.py#L45
      # We re-implement essentially the same forward eval pass except that we
      # skip calling the backbone since we already have the `image_features`,
      # and we also unpack the call to `roi_heads` so that we can keep the `box_features`
      # that are created here:
      # https://github.com/pytorch/vision/blob/
      # 4521f6d152875974e317fa247a633e9ad1ea05c8/torchvision/models/detection/roi_heads.py#L752-L753
  
      image_shapes: List[Tuple[int, int]] = list(
          (int(h), int(w)) for (h, w) in sizes
      )
      image_list = torchvision.models.detection.image_list.ImageList(
          images, image_shapes
      )
  
      # `proposals` is a list of tensors, one tensor per image, each representing a
      # fixed number of proposed regions/boxes.
      # shape (proposals[i]): (proposals_per_image, 4)
      proposals: List[Tensor]
      proposals, _ = self.detector.rpn(image_list, image_features)
  
      # shape: (batch_size * proposals_per_image, *)
      box_features = self.detector.roi_heads.box_roi_pool(
          image_features, proposals, image_shapes
      )
  
      # shape: (batch_size * proposals_per_image, *)
      box_features = self.detector.roi_heads.box_head(box_features)
  
      # shape (class_logits): (batch_size * proposals_per_image, num_classes)
      # shape (box_regression): (batch_size * proposals_per_image, regression_output_size)
      (
          class_logits,
          box_regression,
      ) = self.detector.roi_heads.box_predictor(box_features)
  
      # This step filters down the `proposals` to only detections that reach
      # a certain threshold.
      # Each of these is a list of tensors, one for each image in the batch.
      # shape (boxes[i]): (num_predicted_boxes, 4)
      # shape (features[i]): (num_predicted_boxes, feature_size)
      # shape (scores[i]): (num_predicted_classes,)
      # shape (labels[i]): (num_predicted_classes,)
      boxes, features, scores, labels = self._postprocess_detections(
          class_logits,
          box_features,
          box_regression,
          proposals,
          image_shapes,
      )
  
      return RegionDetectorOutput(features, boxes, scores, labels)
  
imports: import itertools
  import random
  from collections import OrderedDict
  from typing import NamedTuple, Optional, List, Tuple
  import torch
  from torch import nn, FloatTensor, IntTensor, Tensor
  import torch.nn.functional
  import torchvision
  import torchvision.ops.boxes
  from allennlp.common import Registrable
label_desc: Use image node_id 2 for calling the FasterRcnnRegionDetector obj's underlying member method code with example usage: obj.forward(images, sizes, image_features) and returns: RegionDetectorOutput