class_docstr: Head of PAAAssignment: Probabilistic Anchor Assignment with IoU
  Prediction for Object Detection.
  
  Code is modified from the `official github repo
  <https://github.com/kkhoot/PAA/blob/master/paa_core
  /modeling/rpn/paa/loss.py>`_.
  
  More details can be found in the `paper
  <https://arxiv.org/abs/2007.08103>`_ .
  
  Args:
      topk (int): Select topk samples with smallest loss in
          each level.
      score_voting (bool): Whether to use score voting in post-process.
      covariance_type : String describing the type of covariance parameters
          to be used in :class:`sklearn.mixture.GaussianMixture`.
          It must be one of:
  
          - 'full': each component has its own general covariance matrix
          - 'tied': all components share the same general covariance matrix
          - 'diag': each component has its own diagonal covariance matrix
          - 'spherical': each component has its own single variance
          Default: 'diag'. From 'full' to 'spherical', the gmm fitting
          process is faster yet the performance could be influenced. For most
          cases, 'diag' should be a good choice.
class_docstr_tok: ["Head","of","PAAAssignment",":","Probabilistic","Anchor","Assignment","with","IoU","Prediction","for","Object","Detection",".","Code","is","modified","from","the","`","official","github","repo","<","https",":","\/\/github.com\/kkhoot\/PAA\/blob\/master\/paa_core","\/modeling\/rpn\/paa\/loss.py",">","`","_",".","More","details","can","be","found","in","the","`","paper","<","https",":","\/\/arxiv.org\/abs\/2007.08103",">","`","_",".","Args",":","topk","(","int",")",":","Select","topk","samples","with","smallest","loss","in","each","level",".","score_voting","(","bool",")",":","Whether","to","use","score","voting","in","post-process",".","covariance_type",":","String","describing","the","type","of","covariance","parameters","to","be","used","in",":","class",":","`","sklearn.mixture.GaussianMixture","`",".","It","must","be","one","of",":","-","'full","'",":","each","component","has","its","own","general","covariance","matrix","-","'tied","'",":","all","components","share","the","same","general","covariance","matrix","-","'diag","'",":","each","component","has","its","own","diagonal","covariance","matrix","-","'spherical","'",":","each","component","has","its","own","single","variance","Default",":","'diag","'",".","From","'full","'","to","'spherical","'",",","the","gmm","fitting","process","is","faster","yet","the","performance","could","be","influenced",".","For","most","cases",",","'diag","'","should","be","a","good","choice","."]
docstr: Calculate loss of all potential positive samples obtained from first
  match process.
  
  Args:
      anchors (list[Tensor]): Anchors of each scale.
      cls_score (Tensor): Box scores of single image with shape
          (num_anchors, num_classes)
      bbox_pred (Tensor): Box energies / deltas of single image
          with shape (num_anchors, 4)
      label (Tensor): classification target of each anchor with
          shape (num_anchors,)
      label_weight (Tensor): Classification loss weight of each
          anchor with shape (num_anchors).
      bbox_target (dict): Regression target of each anchor with
          shape (num_anchors, 4).
      bbox_weight (Tensor): Bbox weight of each anchor with shape
          (num_anchors, 4).
      pos_inds (Tensor): Index of all positive samples got from
          first assign process.
  
  Returns:
      Tensor: Losses of all positive samples in single image.
docstr_tok: ["Calculate","loss","of","all","potential","positive","samples","obtained","from","first","match","process",".","Args",":","anchors","(","list","[","Tensor","]",")",":","Anchors","of","each","scale",".","cls_score","(","Tensor",")",":","Box","scores","of","single","image","with","shape","(","num_anchors",",","num_classes",")","bbox_pred","(","Tensor",")",":","Box","energies","\/","deltas","of","single","image","with","shape","(","num_anchors",",","4",")","label","(","Tensor",")",":","classification","target","of","each","anchor","with","shape","(","num_anchors",",",")","label_weight","(","Tensor",")",":","Classification","loss","weight","of","each","anchor","with","shape","(","num_anchors",")",".","bbox_target","(","dict",")",":","Regression","target","of","each","anchor","with","shape","(","num_anchors",",","4",")",".","bbox_weight","(","Tensor",")",":","Bbox","weight","of","each","anchor","with","shape","(","num_anchors",",","4",")",".","pos_inds","(","Tensor",")",":","Index","of","all","positive","samples","got","from","first","assign","process",".","Returns",":","Tensor",":","Losses","of","all","positive","samples","in","single","image","."]
code: def get_pos_loss(
      self,
      anchors,
      cls_score,
      bbox_pred,
      label,
      label_weight,
      bbox_target,
      bbox_weight,
      pos_inds,
  ):
      """Calculate loss of all potential positive samples obtained from first
      match process.
  
      Args:
          anchors (list[Tensor]): Anchors of each scale.
          cls_score (Tensor): Box scores of single image with shape
              (num_anchors, num_classes)
          bbox_pred (Tensor): Box energies / deltas of single image
              with shape (num_anchors, 4)
          label (Tensor): classification target of each anchor with
              shape (num_anchors,)
          label_weight (Tensor): Classification loss weight of each
              anchor with shape (num_anchors).
          bbox_target (dict): Regression target of each anchor with
              shape (num_anchors, 4).
          bbox_weight (Tensor): Bbox weight of each anchor with shape
              (num_anchors, 4).
          pos_inds (Tensor): Index of all positive samples got from
              first assign process.
  
      Returns:
          Tensor: Losses of all positive samples in single image.
      """
      if not len(pos_inds):
          return (cls_score.new([]),)
      anchors_all_level = torch.cat(anchors, 0)
      pos_scores = cls_score[pos_inds]
      pos_bbox_pred = bbox_pred[pos_inds]
      pos_label = label[pos_inds]
      pos_label_weight = label_weight[pos_inds]
      pos_bbox_target = bbox_target[pos_inds]
      pos_bbox_weight = bbox_weight[pos_inds]
      pos_anchors = anchors_all_level[pos_inds]
      pos_bbox_pred = self.bbox_coder.decode(pos_anchors, pos_bbox_pred)
  
      # to keep loss dimension
      loss_cls = self.loss_cls(
          pos_scores,
          pos_label,
          pos_label_weight,
          avg_factor=self.loss_cls.loss_weight,
          reduction_override="none",
      )
  
      loss_bbox = self.loss_bbox(
          pos_bbox_pred,
          pos_bbox_target,
          pos_bbox_weight,
          avg_factor=self.loss_cls.loss_weight,
          reduction_override="none",
      )
  
      loss_cls = loss_cls.sum(-1)
      pos_loss = loss_bbox + loss_cls
      return (pos_loss,)
  
file_path: insightface/detection/scrfd/mmdet/models/dense_heads/paa_head.py
imports: import numpy
  import torch
  from mmcv.runner import force_fp32
  from mmdet.core import multi_apply, multiclass_nms
  from mmdet.core.bbox.iou_calculators import bbox_overlaps
  from mmdet.models import HEADS
  from mmdet.models.dense_heads import ATSSHead
label_desc: Use image node_id 3 for calling the PAAHead obj's underlying member method code with example usage: obj.get_pos_loss(anchors, cls_score, bbox_pred, label, label_weight, bbox_target, bbox_weight, pos_inds) and returns: pos_loss, cls_score