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: Get targets for PAA head.
  
  This method is almost the same as `AnchorHead.get_targets()`. We direct
  return the results from _get_targets_single instead map it to levels
  by images_to_levels function.
  
  Args:
      anchor_list (list[list[Tensor]]): Multi level anchors of each
          image. The outer list indicates images, and the inner list
          corresponds to feature levels of the image. Each element of
          the inner list is a tensor of shape (num_anchors, 4).
      valid_flag_list (list[list[Tensor]]): Multi level valid flags of
          each image. The outer list indicates images, and the inner list
          corresponds to feature levels of the image. Each element of
          the inner list is a tensor of shape (num_anchors, )
      gt_bboxes_list (list[Tensor]): Ground truth bboxes of each image.
      img_metas (list[dict]): Meta info of each image.
      gt_bboxes_ignore_list (list[Tensor]): Ground truth bboxes to be
          ignored.
      gt_labels_list (list[Tensor]): Ground truth labels of each box.
      label_channels (int): Channel of label.
      unmap_outputs (bool): Whether to map outputs back to the original
          set of anchors.
  
  Returns:
      tuple: Usually returns a tuple containing learning targets.
  
          - labels (list[Tensor]): Labels of all anchors, each with
              shape (num_anchors,).
          - label_weights (list[Tensor]): Label weights of all anchor.
              each with shape (num_anchors,).
          - bbox_targets (list[Tensor]): BBox targets of all anchors.
              each with shape (num_anchors, 4).
          - bbox_weights (list[Tensor]): BBox weights of all anchors.
              each with shape (num_anchors, 4).
          - pos_inds (list[Tensor]): Contains all index of positive
              sample in all anchor.
          - gt_inds (list[Tensor]): Contains all gt_index of positive
              sample in all anchor.
docstr_tok: ["Get","targets","for","PAA","head",".","This","method","is","almost","the","same","as","`","AnchorHead.get_targets","(",")","`",".","We","direct","return","the","results","from","_get_targets_single","instead","map","it","to","levels","by","images_to_levels","function",".","Args",":","anchor_list","(","list","[","list","[","Tensor","]","]",")",":","Multi","level","anchors","of","each","image",".","The","outer","list","indicates","images",",","and","the","inner","list","corresponds","to","feature","levels","of","the","image",".","Each","element","of","the","inner","list","is","a","tensor","of","shape","(","num_anchors",",","4",")",".","valid_flag_list","(","list","[","list","[","Tensor","]","]",")",":","Multi","level","valid","flags","of","each","image",".","The","outer","list","indicates","images",",","and","the","inner","list","corresponds","to","feature","levels","of","the","image",".","Each","element","of","the","inner","list","is","a","tensor","of","shape","(","num_anchors",",",")","gt_bboxes_list","(","list","[","Tensor","]",")",":","Ground","truth","bboxes","of","each","image",".","img_metas","(","list","[","dict","]",")",":","Meta","info","of","each","image",".","gt_bboxes_ignore_list","(","list","[","Tensor","]",")",":","Ground","truth","bboxes","to","be","ignored",".","gt_labels_list","(","list","[","Tensor","]",")",":","Ground","truth","labels","of","each","box",".","label_channels","(","int",")",":","Channel","of","label",".","unmap_outputs","(","bool",")",":","Whether","to","map","outputs","back","to","the","original","set","of","anchors",".","Returns",":","tuple",":","Usually","returns","a","tuple","containing","learning","targets",".","-","labels","(","list","[","Tensor","]",")",":","Labels","of","all","anchors",",","each","with","shape","(","num_anchors",",",")",".","-","label_weights","(","list","[","Tensor","]",")",":","Label","weights","of","all","anchor",".","each","with","shape","(","num_anchors",",",")",".","-","bbox_targets","(","list","[","Tensor","]",")",":","BBox","targets","of","all","anchors",".","each","with","shape","(","num_anchors",",","4",")",".","-","bbox_weights","(","list","[","Tensor","]",")",":","BBox","weights","of","all","anchors",".","each","with","shape","(","num_anchors",",","4",")",".","-","pos_inds","(","list","[","Tensor","]",")",":","Contains","all","index","of","positive","sample","in","all","anchor",".","-","gt_inds","(","list","[","Tensor","]",")",":","Contains","all","gt_index","of","positive","sample","in","all","anchor","."]
code: def get_targets(
      self,
      anchor_list,
      valid_flag_list,
      gt_bboxes_list,
      img_metas,
      gt_bboxes_ignore_list=None,
      gt_labels_list=None,
      label_channels=1,
      unmap_outputs=True,
  ):
      """Get targets for PAA head.
  
      This method is almost the same as `AnchorHead.get_targets()`. We direct
      return the results from _get_targets_single instead map it to levels
      by images_to_levels function.
  
      Args:
          anchor_list (list[list[Tensor]]): Multi level anchors of each
              image. The outer list indicates images, and the inner list
              corresponds to feature levels of the image. Each element of
              the inner list is a tensor of shape (num_anchors, 4).
          valid_flag_list (list[list[Tensor]]): Multi level valid flags of
              each image. The outer list indicates images, and the inner list
              corresponds to feature levels of the image. Each element of
              the inner list is a tensor of shape (num_anchors, )
          gt_bboxes_list (list[Tensor]): Ground truth bboxes of each image.
          img_metas (list[dict]): Meta info of each image.
          gt_bboxes_ignore_list (list[Tensor]): Ground truth bboxes to be
              ignored.
          gt_labels_list (list[Tensor]): Ground truth labels of each box.
          label_channels (int): Channel of label.
          unmap_outputs (bool): Whether to map outputs back to the original
              set of anchors.
  
      Returns:
          tuple: Usually returns a tuple containing learning targets.
  
              - labels (list[Tensor]): Labels of all anchors, each with
                  shape (num_anchors,).
              - label_weights (list[Tensor]): Label weights of all anchor.
                  each with shape (num_anchors,).
              - bbox_targets (list[Tensor]): BBox targets of all anchors.
                  each with shape (num_anchors, 4).
              - bbox_weights (list[Tensor]): BBox weights of all anchors.
                  each with shape (num_anchors, 4).
              - pos_inds (list[Tensor]): Contains all index of positive
                  sample in all anchor.
              - gt_inds (list[Tensor]): Contains all gt_index of positive
                  sample in all anchor.
      """
  
      num_imgs = len(img_metas)
      assert len(anchor_list) == len(valid_flag_list) == num_imgs
      concat_anchor_list = []
      concat_valid_flag_list = []
      for i in range(num_imgs):
          assert len(anchor_list[i]) == len(valid_flag_list[i])
          concat_anchor_list.append(torch.cat(anchor_list[i]))
          concat_valid_flag_list.append(torch.cat(valid_flag_list[i]))
  
      # compute targets for each image
      if gt_bboxes_ignore_list is None:
          gt_bboxes_ignore_list = [None for _ in range(num_imgs)]
      if gt_labels_list is None:
          gt_labels_list = [None for _ in range(num_imgs)]
      results = multi_apply(
          self._get_targets_single,
          concat_anchor_list,
          concat_valid_flag_list,
          gt_bboxes_list,
          gt_bboxes_ignore_list,
          gt_labels_list,
          img_metas,
          label_channels=label_channels,
          unmap_outputs=unmap_outputs,
      )
  
      (
          labels,
          label_weights,
          bbox_targets,
          bbox_weights,
          valid_pos_inds,
          valid_neg_inds,
          sampling_result,
      ) = results
  
      # Due to valid flag of anchors, we have to calculate the real pos_inds
      # in origin anchor set.
      pos_inds = []
      for i, single_labels in enumerate(labels):
          pos_mask = (0 <= single_labels) & (
              single_labels < self.num_classes
          )
          pos_inds.append(pos_mask.nonzero().view(-1))
  
      gt_inds = [item.pos_assigned_gt_inds for item in sampling_result]
      return (
          labels,
          label_weights,
          bbox_targets,
          bbox_weights,
          pos_inds,
          gt_inds,
      )
  
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 6 for calling the PAAHead obj's underlying member method code with example usage: obj.get_targets(anchor_list, valid_flag_list, gt_bboxes_list, img_metas, gt_bboxes_ignore_list, gt_labels_list, label_channels, unmap_outputs) and returns: labels,  label_weights,  bbox_targets,  bbox_weights,  pos_inds,  gt_inds