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: Transform outputs for a single batch item into labeled boxes.
  
  This method is almost same as `ATSSHead._get_bboxes_single()`.
  We use sqrt(iou_preds * cls_scores) in NMS process instead of just
  cls_scores. Besides, score voting is used when `` score_voting``
  is set to True.
docstr_tok: ["Transform","outputs","for","a","single","batch","item","into","labeled","boxes",".","This","method","is","almost","same","as","`","ATSSHead._get_bboxes_single","(",")","`",".","We","use","sqrt","(","iou_preds","*","cls_scores",")","in","NMS","process","instead","of","just","cls_scores",".","Besides",",","score","voting","is","used","when","``","score_voting","``","is","set","to","True","."]
code: def _get_bboxes_single(
      self,
      cls_scores,
      bbox_preds,
      iou_preds,
      mlvl_anchors,
      img_shape,
      scale_factor,
      cfg,
      rescale=False,
      with_nms=True,
  ):
      """Transform outputs for a single batch item into labeled boxes.
  
      This method is almost same as `ATSSHead._get_bboxes_single()`.
      We use sqrt(iou_preds * cls_scores) in NMS process instead of just
      cls_scores. Besides, score voting is used when `` score_voting``
      is set to True.
      """
      assert with_nms, 'PAA only supports "with_nms=True" now'
      assert len(cls_scores) == len(bbox_preds) == len(mlvl_anchors)
      mlvl_bboxes = []
      mlvl_scores = []
      mlvl_iou_preds = []
      for cls_score, bbox_pred, iou_preds, anchors in zip(
          cls_scores, bbox_preds, iou_preds, mlvl_anchors
      ):
          assert cls_score.size()[-2:] == bbox_pred.size()[-2:]
  
          scores = (
              cls_score.permute(1, 2, 0)
              .reshape(-1, self.cls_out_channels)
              .sigmoid()
          )
          bbox_pred = bbox_pred.permute(1, 2, 0).reshape(-1, 4)
          iou_preds = iou_preds.permute(1, 2, 0).reshape(-1).sigmoid()
          nms_pre = cfg.get("nms_pre", -1)
          if nms_pre > 0 and scores.shape[0] > nms_pre:
              max_scores, _ = (
                  (scores * iou_preds[:, None]).sqrt().max(dim=1)
              )
              _, topk_inds = max_scores.topk(nms_pre)
              anchors = anchors[topk_inds, :]
              bbox_pred = bbox_pred[topk_inds, :]
              scores = scores[topk_inds, :]
              iou_preds = iou_preds[topk_inds]
  
          bboxes = self.bbox_coder.decode(
              anchors, bbox_pred, max_shape=img_shape
          )
          mlvl_bboxes.append(bboxes)
          mlvl_scores.append(scores)
          mlvl_iou_preds.append(iou_preds)
  
      mlvl_bboxes = torch.cat(mlvl_bboxes)
      if rescale:
          mlvl_bboxes /= mlvl_bboxes.new_tensor(scale_factor)
      mlvl_scores = torch.cat(mlvl_scores)
      # Add a dummy background class to the backend when using sigmoid
      # remind that we set FG labels to [0, num_class-1] since mmdet v2.0
      # BG cat_id: num_class
      padding = mlvl_scores.new_zeros(mlvl_scores.shape[0], 1)
      mlvl_scores = torch.cat([mlvl_scores, padding], dim=1)
      mlvl_iou_preds = torch.cat(mlvl_iou_preds)
      mlvl_nms_scores = (mlvl_scores * mlvl_iou_preds[:, None]).sqrt()
      det_bboxes, det_labels = multiclass_nms(
          mlvl_bboxes,
          mlvl_nms_scores,
          cfg.score_thr,
          cfg.nms,
          cfg.max_per_img,
          score_factors=None,
      )
      if self.with_score_voting:
          det_bboxes, det_labels = self.score_voting(
              det_bboxes,
              det_labels,
              mlvl_bboxes,
              mlvl_nms_scores,
              cfg.score_thr,
          )
  
      return det_bboxes, det_labels
  
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 8 for calling the PAAHead obj's underlying member method code with example usage: obj._get_bboxes_single(cls_scores, bbox_preds, iou_preds, mlvl_anchors, img_shape, scale_factor, cfg, rescale, with_nms) and returns: det_bboxes,  det_labels