class_docstr: Anchor-based head (RPN, RetinaNet, SSD, etc.).
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      feat_channels (int): Number of hidden channels. Used in child classes.
      anchor_generator (dict): Config dict for anchor generator
      bbox_coder (dict): Config of bounding box coder.
      reg_decoded_bbox (bool): If true, the regression loss would be
          applied on decoded bounding boxes. Default: False
      loss_cls (dict): Config of classification loss.
      loss_bbox (dict): Config of localization loss.
      train_cfg (dict): Training config of anchor head.
      test_cfg (dict): Testing config of anchor head.
docstr: Compute loss of a single scale level.
  
  Args:
      cls_score (Tensor): Box scores for each scale level
          Has shape (N, num_anchors * num_classes, H, W).
      bbox_pred (Tensor): Box energies / deltas for each scale
          level with shape (N, num_anchors * 4, H, W).
      anchors (Tensor): Box reference for each scale level with shape
          (N, num_total_anchors, 4).
      labels (Tensor): Labels of each anchors with shape
          (N, num_total_anchors).
      label_weights (Tensor): Label weights of each anchor with shape
          (N, num_total_anchors)
      bbox_targets (Tensor): BBox regression targets of each anchor wight
          shape (N, num_total_anchors, 4).
      bbox_weights (Tensor): BBox regression loss weights of each anchor
          with shape (N, num_total_anchors, 4).
      num_total_samples (int): If sampling, num total samples equal to
          the number of total anchors; Otherwise, it is the number of
          positive anchors.
  
  Returns:
      dict[str, Tensor]: A dictionary of loss components.
docstr_tok: ["Compute","loss","of","a","single","scale","level",".","Args",":","cls_score","(","Tensor",")",":","Box","scores","for","each","scale","level","Has","shape","(","N",",","num_anchors","*","num_classes",",","H",",","W",")",".","bbox_pred","(","Tensor",")",":","Box","energies","\/","deltas","for","each","scale","level","with","shape","(","N",",","num_anchors","*","4",",","H",",","W",")",".","anchors","(","Tensor",")",":","Box","reference","for","each","scale","level","with","shape","(","N",",","num_total_anchors",",","4",")",".","labels","(","Tensor",")",":","Labels","of","each","anchors","with","shape","(","N",",","num_total_anchors",")",".","label_weights","(","Tensor",")",":","Label","weights","of","each","anchor","with","shape","(","N",",","num_total_anchors",")","bbox_targets","(","Tensor",")",":","BBox","regression","targets","of","each","anchor","wight","shape","(","N",",","num_total_anchors",",","4",")",".","bbox_weights","(","Tensor",")",":","BBox","regression","loss","weights","of","each","anchor","with","shape","(","N",",","num_total_anchors",",","4",")",".","num_total_samples","(","int",")",":","If","sampling",",","num","total","samples","equal","to","the","number","of","total","anchors",";","Otherwise",",","it","is","the","number","of","positive","anchors",".","Returns",":","dict","[","str",",","Tensor","]",":","A","dictionary","of","loss","components","."]
code: def loss_single(
      self,
      cls_score,
      bbox_pred,
      anchors,
      labels,
      label_weights,
      bbox_targets,
      bbox_weights,
      num_total_samples,
  ):
      """Compute loss of a single scale level.
  
      Args:
          cls_score (Tensor): Box scores for each scale level
              Has shape (N, num_anchors * num_classes, H, W).
          bbox_pred (Tensor): Box energies / deltas for each scale
              level with shape (N, num_anchors * 4, H, W).
          anchors (Tensor): Box reference for each scale level with shape
              (N, num_total_anchors, 4).
          labels (Tensor): Labels of each anchors with shape
              (N, num_total_anchors).
          label_weights (Tensor): Label weights of each anchor with shape
              (N, num_total_anchors)
          bbox_targets (Tensor): BBox regression targets of each anchor wight
              shape (N, num_total_anchors, 4).
          bbox_weights (Tensor): BBox regression loss weights of each anchor
              with shape (N, num_total_anchors, 4).
          num_total_samples (int): If sampling, num total samples equal to
              the number of total anchors; Otherwise, it is the number of
              positive anchors.
  
      Returns:
          dict[str, Tensor]: A dictionary of loss components.
      """
      # classification loss
      labels = labels.reshape(-1)
      label_weights = label_weights.reshape(-1)
      cls_score = cls_score.permute(0, 2, 3, 1).reshape(
          -1, self.cls_out_channels
      )
      loss_cls = self.loss_cls(
          cls_score, labels, label_weights, avg_factor=num_total_samples
      )
      # regression loss
      bbox_targets = bbox_targets.reshape(-1, 4)
      bbox_weights = bbox_weights.reshape(-1, 4)
      bbox_pred = bbox_pred.permute(0, 2, 3, 1).reshape(-1, 4)
      if self.reg_decoded_bbox:
          anchors = anchors.reshape(-1, 4)
          bbox_pred = self.bbox_coder.decode(anchors, bbox_pred)
      loss_bbox = self.loss_bbox(
          bbox_pred,
          bbox_targets,
          bbox_weights,
          avg_factor=num_total_samples,
      )
      return loss_cls, loss_bbox
  
imports: import torch
  import torch.nn
  from mmcv.cnn import normal_init
  from mmcv.runner import force_fp32
  from mmdet.core import anchor_inside_flags, build_anchor_generator, build_assigner, build_bbox_coder, build_sampler, images_to_levels, multi_apply, multiclass_nms, unmap
  from ..builder import HEADS, build_loss
  from .base_dense_head import BaseDenseHead
  from .dense_test_mixins import BBoxTestMixin
label_desc: Use image node_id 9 for calling the AnchorHead obj's underlying member method code with example usage: obj.loss_single(cls_score, bbox_pred, anchors, labels, label_weights, bbox_targets, bbox_weights, num_total_samples) and returns: loss_cls,  loss_bbox