class_docstr: A classification 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
      num_classes (int): number of classes to be predicted
class_docstr_tok: ["A","classification","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","num_classes","(","int",")",":","number","of","classes","to","be","predicted"]
code: def compute_loss(
      self,
      targets: List[Dict[str, Tensor]],
      head_outputs: Dict[str, Tensor],
      matched_idxs: List[Tensor],
  ) -> Tensor:
      losses = []
      cls_logits = head_outputs["cls_logits"]
      for (
          targets_per_img,
          cls_logits_per_img,
          matched_idxs_per_img,
      ) in zip(targets, cls_logits, matched_idxs):
          # determine only the foreground
          # 找出所有前景目标
          foreground_idxs_per_img = torch.ge(
              matched_idxs_per_img, 0
          )  # ge: >=
          num_foreground = foreground_idxs_per_img.sum()
  
          # create the target classification
          gt_classes_target = torch.zeros_like(cls_logits_per_img)
          gt_classes_target[
              foreground_idxs_per_img,
              targets_per_img["labels"][
                  matched_idxs_per_img[foreground_idxs_per_img]
              ],
          ] = 1.0
  
          # find indices for which anchors should be ignored
          # 忽略iou在[0.4, 0.5)之间的anchors
          valid_idxs_per_img = torch.ne(
              matched_idxs_per_img, self.BETWEEN_THRESHOLDS
          )  # ne: !=
  
          # compute the classification loss
          losses.append(
              sigmoid_focal_loss(
                  cls_logits_per_img[valid_idxs_per_img],
                  gt_classes_target[valid_idxs_per_img],
                  reduction="sum",
              )
              / max(1, num_foreground)
          )  # 注意这里除以的是正样本的个数
  
      # len(targets): batch_size
      return _sum(losses) / 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 RetinaNetClassificationHead obj's underlying member method code with example usage: obj.compute_loss(targets, head_outputs, matched_idxs) and returns: unknown