code: def fastrcnn_loss(
      class_logits, box_regression, labels, regression_targets
  ):
      # type: (Tensor, Tensor, List[Tensor], List[Tensor]) -> Tuple[Tensor, Tensor]
      """
      Computes the loss for Faster R-CNN.
  
      Arguments:
          class_logits : 预测类别概率信息，shape=[num_anchors, num_classes]
          box_regression : 预测边目标界框回归信息
          labels : 真实类别信息
          regression_targets : 真实目标边界框信息
  
      Returns:
          classification_loss (Tensor)
          box_loss (Tensor)
      """
  
      labels = torch.cat(labels, dim=0)
      regression_targets = torch.cat(regression_targets, dim=0)
  
      # 计算类别损失信息
      classification_loss = F.cross_entropy(class_logits, labels)
  
      # get indices that correspond to the regression targets for
      # the corresponding ground truth labels, to be used with
      # advanced indexing
      # 返回标签类别大于0的索引
      # sampled_pos_inds_subset = torch.nonzero(torch.gt(labels, 0)).squeeze(1)
      sampled_pos_inds_subset = torch.where(torch.gt(labels, 0))[0]
  
      # 返回标签类别大于0位置的类别信息
      labels_pos = labels[sampled_pos_inds_subset]
  
      # shape=[num_proposal, num_classes]
      N, num_classes = class_logits.shape
      box_regression = box_regression.reshape(N, -1, 4)
  
      # 计算边界框损失信息
      box_loss = (
          det_utils.smooth_l1_loss(
              # 获取指定索引proposal的指定类别box信息
              box_regression[sampled_pos_inds_subset, labels_pos],
              regression_targets[sampled_pos_inds_subset],
              beta=1 / 9,
              size_average=False,
          )
          / labels.numel()
      )
  
      return classification_loss, box_loss
  
imports: from typing import Optional, List, Dict, Tuple
  import torch
  from torch import Tensor
  import torch.nn.functional
  from torchvision.ops import roi_align
  from .None import det_utils
  from .None import boxes
label_desc: Use image node_id 1 for calling a global function with example usage: fastrcnn_loss(class_logits, box_regression, labels, regression_targets) and returns: classification_loss,  box_loss