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. Defaults to None.
      init_cfg (:obj:`ConfigDict` or dict or list[:obj:`ConfigDict` or             dict]): Initialization config dict.
      **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",".","Defaults","to","None",".","init_cfg","(",":","obj",":","`","ConfigDict","`","or","dict","or","list","[",":","obj",":","`","ConfigDict","`","or","dict","]",")",":","Initialization","config","dict",".","*","*","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:
      Tensor: 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",":","Tensor",":","shape","(","num_gt",")",",","average","loss","of","each","gt","in","this","level"]
code: def collect_loss_level_single(
      self,
      cls_loss: Tensor,
      reg_loss: Tensor,
      assigned_gt_inds: Tensor,
      labels_seq: Tensor,
  ) -> Tensor:
      """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:
          Tensor: 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_,)
  
imports: from typing import Dict, List, Optional, Tuple
  import numpy
  import torch
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.utils import InstanceList, OptInstanceList, OptMultiConfig
  from ..losses.accuracy import accuracy
  from ..losses.utils import weight_reduce_loss
  from ..task_modules.prior_generators import anchor_inside_flags
  from ..utils import images_to_levels, multi_apply, unmap
  from .retina_head import RetinaHead
label_desc: Use image node_id 6 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_