class_docstr: Implements Region Proposal Network (RPN).
  
  Args:
      anchor_generator (AnchorGenerator): module that generates the anchors for a set of feature
          maps.
      head (nn.Module): module that computes the objectness and regression deltas
      fg_iou_thresh (float): minimum IoU between the anchor and the GT box so that they can be
          considered as positive during training of the RPN.
      bg_iou_thresh (float): maximum IoU between the anchor and the GT box so that they can be
          considered as negative during training of the RPN.
      batch_size_per_image (int): number of anchors that are sampled during training of the RPN
          for computing the loss
      positive_fraction (float): proportion of positive anchors in a mini-batch during training
          of the RPN
      pre_nms_top_n (Dict[str, int]): number of proposals to keep before applying NMS. It should
          contain two fields: training and testing, to allow for different values depending
          on training or evaluation
      post_nms_top_n (Dict[str, int]): number of proposals to keep after applying NMS. It should
          contain two fields: training and testing, to allow for different values depending
          on training or evaluation
      nms_thresh (float): NMS threshold used for postprocessing the RPN proposals
docstr: Args:
      images (ImageList): images for which we want to compute the predictions
      features (Dict[str, Tensor]): features computed from the images that are
          used for computing the predictions. Each tensor in the list
          correspond to different feature levels
      targets (List[Dict[str, Tensor]]): ground-truth boxes present in the image (optional).
          If provided, each element in the dict should contain a field `boxes`,
          with the locations of the ground-truth boxes.
  
  Returns:
      boxes (List[Tensor]): the predicted boxes from the RPN, one Tensor per
          image.
      losses (Dict[str, Tensor]): the losses for the model during training. During
          testing, it is an empty dict.
docstr_tok: ["Args",":","images","(","ImageList",")",":","images","for","which","we","want","to","compute","the","predictions","features","(","Dict","[","str",",","Tensor","]",")",":","features","computed","from","the","images","that","are","used","for","computing","the","predictions",".","Each","tensor","in","the","list","correspond","to","different","feature","levels","targets","(","List","[","Dict","[","str",",","Tensor","]","]",")",":","ground-truth","boxes","present","in","the","image","(","optional",")",".","If","provided",",","each","element","in","the","dict","should","contain","a","field","`","boxes","`",",","with","the","locations","of","the","ground-truth","boxes",".","Returns",":","boxes","(","List","[","Tensor","]",")",":","the","predicted","boxes","from","the","RPN",",","one","Tensor","per","image",".","losses","(","Dict","[","str",",","Tensor","]",")",":","the","losses","for","the","model","during","training",".","During","testing",",","it","is","an","empty","dict","."]
code: def forward(
      self,
      images: ImageList,
      features: Dict[str, Tensor],
      targets: Optional[List[Dict[str, Tensor]]] = None,
  ) -> Tuple[List[Tensor], Dict[str, Tensor]]:
      """
      Args:
          images (ImageList): images for which we want to compute the predictions
          features (Dict[str, Tensor]): features computed from the images that are
              used for computing the predictions. Each tensor in the list
              correspond to different feature levels
          targets (List[Dict[str, Tensor]]): ground-truth boxes present in the image (optional).
              If provided, each element in the dict should contain a field `boxes`,
              with the locations of the ground-truth boxes.
  
      Returns:
          boxes (List[Tensor]): the predicted boxes from the RPN, one Tensor per
              image.
          losses (Dict[str, Tensor]): the losses for the model during training. During
              testing, it is an empty dict.
      """
      # RPN uses all feature maps that are available
      features = list(features.values())
      objectness, pred_bbox_deltas = self.head(features)
      anchors = self.anchor_generator(images, features)
  
      num_images = len(anchors)
      num_anchors_per_level_shape_tensors = [
          o[0].shape for o in objectness
      ]
      num_anchors_per_level = [
          s[0] * s[1] * s[2]
          for s in num_anchors_per_level_shape_tensors
      ]
      objectness, pred_bbox_deltas = concat_box_prediction_layers(
          objectness, pred_bbox_deltas
      )
      # apply pred_bbox_deltas to anchors to obtain the decoded proposals
      # note that we detach the deltas because Faster R-CNN do not backprop through
      # the proposals
      proposals = self.box_coder.decode(
          pred_bbox_deltas.detach(), anchors
      )
      proposals = proposals.view(num_images, -1, 4)
      boxes, scores = self.filter_proposals(
          proposals,
          objectness,
          images.image_sizes,
          num_anchors_per_level,
      )
  
      losses = {}
      if self.training:
          if targets is None:
              raise ValueError("targets should not be None")
          labels, matched_gt_boxes = self.assign_targets_to_anchors(
              anchors, targets
          )
          regression_targets = self.box_coder.encode(
              matched_gt_boxes, anchors
          )
          loss_objectness, loss_rpn_box_reg = self.compute_loss(
              objectness, pred_bbox_deltas, labels, regression_targets
          )
          losses = {
              "loss_objectness": loss_objectness,
              "loss_rpn_box_reg": loss_rpn_box_reg,
          }
      return boxes, losses
  
imports: from typing import Dict, List, Optional, Tuple
  import torch
  from torch import nn, Tensor
  from torch.nn import functional
  from torchvision.ops import boxes, Conv2dNormActivation
  from .None import _utils
  from .anchor_utils import AnchorGenerator
  from .image_list import ImageList
label_desc: Use image node_id 8 for calling the RegionProposalNetwork obj's underlying member method code with example usage: obj.forward(images, features, targets) and returns: boxes,  losses