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.
  
      Args:
          class_logits (Tensor)
          box_regression (Tensor)
          labels (list[BoxList])
          regression_targets (Tensor)
  
      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
      sampled_pos_inds_subset = torch.where(labels > 0)[0]
      labels_pos = labels[sampled_pos_inds_subset]
      N, num_classes = class_logits.shape
      box_regression = box_regression.reshape(
          N, box_regression.size(-1) // 4, 4
      )
  
      box_loss = F.smooth_l1_loss(
          box_regression[sampled_pos_inds_subset, labels_pos],
          regression_targets[sampled_pos_inds_subset],
          beta=1 / 9,
          reduction="sum",
      )
      box_loss = box_loss / labels.numel()
  
      return classification_loss, box_loss
  
imports: from typing import Dict, List, Optional, Tuple
  import torch
  import torch.nn.functional
  import torchvision
  from torch import nn, Tensor
  from torchvision.ops import boxes, roi_align
  from .None import _utils
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