class_docstr: A regression head for use in RetinaNet.
  
  Args:
      in_channels (int): number of channels of the input feature
      num_anchors (int): number of anchors to be predicted
class_docstr_tok: ["A","regression","head","for","use","in","RetinaNet",".","Args",":","in_channels","(","int",")",":","number","of","channels","of","the","input","feature","num_anchors","(","int",")",":","number","of","anchors","to","be","predicted"]
code: def compute_loss(
      self,
      targets: List[Dict[str, Tensor]],
      head_outputs: Dict[str, Tensor],
      anchors: List[Tensor],
      matched_idxs: List[Tensor],
  ) -> Tensor:
      losses = []
  
      bbox_regression = head_outputs["bbox_regression"]
      for (
          targets_per_img,
          bbox_regression_per_img,
          anchors_per_img,
          matched_idxs_per_img,
      ) in zip(targets, bbox_regression, anchors, matched_idxs):
          # determine only the foreground indices, ignore the rest
          foreground_idxs_per_img = torch.where(
              torch.ge(matched_idxs_per_img, 0)
          )[
              0
          ]  # ge: >=
          num_foreground = foreground_idxs_per_img.numel()
  
          # select only the foreground boxes
          matched_gt_boxes_per_img = targets_per_img["boxes"][
              matched_idxs_per_img[foreground_idxs_per_img]
          ]
          bbox_regression_per_img = bbox_regression_per_img[
              foreground_idxs_per_img, :
          ]
          anchors_per_img = anchors_per_img[foreground_idxs_per_img, :]
  
          # compute the regression targets
          targets_regression = self.bbox_coder.encode_single(
              matched_gt_boxes_per_img, anchors_per_img
          )
  
          # compute the box regression loss
          losses.append(
              torch.nn.functional.l1_loss(
                  bbox_regression_per_img,
                  targets_regression,
                  reduction="sum",
              )
              / max(1, num_foreground)
          )
  
      return _sum(losses) / max(1, len(targets))
  
imports: import math
  import warnings
  from collections import OrderedDict
  from typing import Dict, List, Tuple, Optional, Union
  import torch
  from torch import nn, Tensor
  from .None import det_utils
  from .anchor_utils import AnchorsGenerator
  from .None import boxes
  from .losses import sigmoid_focal_loss
  from .transform import GeneralizedRCNNTransform
label_desc: Use image node_id 2 for calling the RetinaNetRegressionHead obj's underlying member method code with example usage: obj.compute_loss(targets, head_outputs, anchors, matched_idxs) and returns: unknown