class_docstr: Anchor-free head used in `FSAF <https://arxiv.org/abs/1903.00621>`_.
  
  The head contains two subnetworks. The first classifies anchor boxes and
  the second regresses deltas for the anchors (num_anchors is 1 for anchor-
  free methods)
  
  Args:
      *args: Same as its base class in :class:`RetinaHead`
      score_threshold (float, optional): The score_threshold to calculate
          positive recall. If given, prediction scores lower than this value
          is counted as incorrect prediction. Default to None.
      **kwargs: Same as its base class in :class:`RetinaHead`
  
  Example:
      >>> import torch
      >>> self = FSAFHead(11, 7)
      >>> x = torch.rand(1, 7, 32, 32)
      >>> cls_score, bbox_pred = self.forward_single(x)
      >>> # Each anchor predicts a score for each class except background
      >>> cls_per_anchor = cls_score.shape[1] / self.num_anchors
      >>> box_per_anchor = bbox_pred.shape[1] / self.num_anchors
      >>> assert cls_per_anchor == self.num_classes
      >>> assert box_per_anchor == 4
class_docstr_tok: ["Anchor-free","head","used","in","`","FSAF","<","https",":","\/\/arxiv.org\/abs\/1903.00621",">","`","_",".","The","head","contains","two","subnetworks",".","The","first","classifies","anchor","boxes","and","the","second","regresses","deltas","for","the","anchors","(","num_anchors","is","1","for","anchor-","free","methods",")","Args",":","*","args",":","Same","as","its","base","class","in",":","class",":","`","RetinaHead","`","score_threshold","(","float",",","optional",")",":","The","score_threshold","to","calculate","positive","recall",".","If","given",",","prediction","scores","lower","than","this","value","is","counted","as","incorrect","prediction",".","Default","to","None",".","*","*","kwargs",":","Same","as","its","base","class","in",":","class",":","`","RetinaHead","`","Example",":",">",">",">","import","torch",">",">",">","self","=","FSAFHead","(","11",",","7",")",">",">",">","x","=","torch.rand","(","1",",","7",",","32",",","32",")",">",">",">","cls_score",",","bbox_pred","=","self.forward_single","(","x",")",">",">",">","#","Each","anchor","predicts","a","score","for","each","class","except","background",">",">",">","cls_per_anchor","=","cls_score.shape","[","1","]","\/","self.num_anchors",">",">",">","box_per_anchor","=","bbox_pred.shape","[","1","]","\/","self.num_anchors",">",">",">","assert","cls_per_anchor","==","self.num_classes",">",">",">","assert","box_per_anchor","==","4"]
docstr: Get the average loss in each FPN level w.r.t. each gt label.
  
  Args:
      cls_loss (Tensor): Classification loss of each feature map pixel,
        shape (num_anchor, num_class)
      reg_loss (Tensor): Regression loss of each feature map pixel,
        shape (num_anchor, 4)
      assigned_gt_inds (Tensor): It indicates which gt the prior is
        assigned to (0-based, -1: no assignment). shape (num_anchor),
      labels_seq: The rank of labels. shape (num_gt)
  
  Returns:
      shape: (num_gt), average loss of each gt in this level
docstr_tok: ["Get","the","average","loss","in","each","FPN","level","w.r.t",".","each","gt","label",".","Args",":","cls_loss","(","Tensor",")",":","Classification","loss","of","each","feature","map","pixel",",","shape","(","num_anchor",",","num_class",")","reg_loss","(","Tensor",")",":","Regression","loss","of","each","feature","map","pixel",",","shape","(","num_anchor",",","4",")","assigned_gt_inds","(","Tensor",")",":","It","indicates","which","gt","the","prior","is","assigned","to","(","0-based",",","-1",":","no","assignment",")",".","shape","(","num_anchor",")",",","labels_seq",":","The","rank","of","labels",".","shape","(","num_gt",")","Returns",":","shape",":","(","num_gt",")",",","average","loss","of","each","gt","in","this","level"]
code: def collect_loss_level_single(
      self, cls_loss, reg_loss, assigned_gt_inds, labels_seq
  ):
      """Get the average loss in each FPN level w.r.t. each gt label.
  
      Args:
          cls_loss (Tensor): Classification loss of each feature map pixel,
            shape (num_anchor, num_class)
          reg_loss (Tensor): Regression loss of each feature map pixel,
            shape (num_anchor, 4)
          assigned_gt_inds (Tensor): It indicates which gt the prior is
            assigned to (0-based, -1: no assignment). shape (num_anchor),
          labels_seq: The rank of labels. shape (num_gt)
  
      Returns:
          shape: (num_gt), average loss of each gt in this level
      """
      if len(reg_loss.shape) == 2:  # iou loss has shape (num_prior, 4)
          reg_loss = reg_loss.sum(dim=-1)  # sum loss in tblr dims
      if len(cls_loss.shape) == 2:
          cls_loss = cls_loss.sum(dim=-1)  # sum loss in class dims
      loss = cls_loss + reg_loss
      assert loss.size(0) == assigned_gt_inds.size(0)
      # Default loss value is 1e6 for a layer where no anchor is positive
      #  to ensure it will not be chosen to back-propagate gradient
      losses_ = loss.new_full(labels_seq.shape, 1e6)
      for i, l in enumerate(labels_seq):
          match = assigned_gt_inds == l
          if match.any():
              losses_[i] = loss[match].mean()
      return (losses_,)
  
file_path: insightface/detection/scrfd/mmdet/models/dense_heads/fsaf_head.py
imports: import numpy
  import torch
  from mmcv.cnn import normal_init
  from mmcv.runner import force_fp32
  from mmdet.core import anchor_inside_flags, images_to_levels, multi_apply, unmap
  from ..builder import HEADS
  from ..losses.accuracy import accuracy
  from ..losses.utils import weight_reduce_loss
  from .retina_head import RetinaHead
label_desc: Use image node_id 7 for calling the FSAFHead obj's underlying member method code with example usage: obj.collect_loss_level_single(cls_loss, reg_loss, assigned_gt_inds, labels_seq) and returns: losses_