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:
      objectness (Tensor)
      pred_bbox_deltas (Tensor)
      labels (List[Tensor])
      regression_targets (List[Tensor])
  
  Returns:
      objectness_loss (Tensor)
      box_loss (Tensor)
docstr_tok: ["Args",":","objectness","(","Tensor",")","pred_bbox_deltas","(","Tensor",")","labels","(","List","[","Tensor","]",")","regression_targets","(","List","[","Tensor","]",")","Returns",":","objectness_loss","(","Tensor",")","box_loss","(","Tensor",")"]
code: def compute_loss(
      self,
      objectness: Tensor,
      pred_bbox_deltas: Tensor,
      labels: List[Tensor],
      regression_targets: List[Tensor],
  ) -> Tuple[Tensor, Tensor]:
      """
      Args:
          objectness (Tensor)
          pred_bbox_deltas (Tensor)
          labels (List[Tensor])
          regression_targets (List[Tensor])
  
      Returns:
          objectness_loss (Tensor)
          box_loss (Tensor)
      """
  
      sampled_pos_inds, sampled_neg_inds = self.fg_bg_sampler(labels)
      sampled_pos_inds = torch.where(
          torch.cat(sampled_pos_inds, dim=0)
      )[0]
      sampled_neg_inds = torch.where(
          torch.cat(sampled_neg_inds, dim=0)
      )[0]
  
      sampled_inds = torch.cat(
          [sampled_pos_inds, sampled_neg_inds], dim=0
      )
  
      objectness = objectness.flatten()
  
      labels = torch.cat(labels, dim=0)
      regression_targets = torch.cat(regression_targets, dim=0)
  
      box_loss = F.smooth_l1_loss(
          pred_bbox_deltas[sampled_pos_inds],
          regression_targets[sampled_pos_inds],
          beta=1 / 9,
          reduction="sum",
      ) / (sampled_inds.numel())
  
      objectness_loss = F.binary_cross_entropy_with_logits(
          objectness[sampled_inds], labels[sampled_inds]
      )
  
      return objectness_loss, box_loss
  
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 7 for calling the RegionProposalNetwork obj's underlying member method code with example usage: obj.compute_loss(objectness, pred_bbox_deltas, labels, regression_targets) and returns: objectness_loss,  box_loss