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.
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, )
      batch_gt_instances (list[:obj:`InstanceData`]): Batch of
          gt_instance. It usually includes ``bboxes`` and ``labels``
          attributes.
      batch_img_metas (list[dict]): Meta information of each image, e.g.,
          image size, scaling factor, etc.
      batch_gt_instances_ignore (list[:obj:`InstanceData`], optional):
          Batch of gt_instances_ignore. It includes ``bboxes`` attribute
          data that is ignored during training and testing.
          Defaults to None.
      unmap_outputs (bool): Whether to map outputs back to the original
          set of anchors. Defaults to True.
  
  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",",",")","batch_gt_instances","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","Batch","of","gt_instance",".","It","usually","includes","``","bboxes","``","and","``","labels","``","attributes",".","batch_img_metas","(","list","[","dict","]",")",":","Meta","information","of","each","image",",","e.g.",",","image","size",",","scaling","factor",",","etc",".","batch_gt_instances_ignore","(","list","[",":","obj",":","`","InstanceData","`","]",",","optional",")",":","Batch","of","gt_instances_ignore",".","It","includes","``","bboxes","``","attribute","data","that","is","ignored","during","training","and","testing",".","Defaults","to","None",".","unmap_outputs","(","bool",")",":","Whether","to","map","outputs","back","to","the","original","set","of","anchors",".","Defaults","to","True",".","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: List[List[Tensor]],
      valid_flag_list: List[List[Tensor]],
      batch_gt_instances: InstanceList,
      batch_img_metas: List[dict],
      batch_gt_instances_ignore: OptInstanceList = None,
      unmap_outputs: bool = True,
  ) -> tuple:
      """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, )
          batch_gt_instances (list[:obj:`InstanceData`]): Batch of
              gt_instance. It usually includes ``bboxes`` and ``labels``
              attributes.
          batch_img_metas (list[dict]): Meta information of each image, e.g.,
              image size, scaling factor, etc.
          batch_gt_instances_ignore (list[:obj:`InstanceData`], optional):
              Batch of gt_instances_ignore. It includes ``bboxes`` attribute
              data that is ignored during training and testing.
              Defaults to None.
          unmap_outputs (bool): Whether to map outputs back to the original
              set of anchors. Defaults to True.
  
      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(batch_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 batch_gt_instances_ignore is None:
          batch_gt_instances_ignore = [None] * num_imgs
      results = multi_apply(
          self._get_targets_single,
          concat_anchor_list,
          concat_valid_flag_list,
          batch_gt_instances,
          batch_img_metas,
          batch_gt_instances_ignore,
          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,
      )
  
imports: from typing import List, Optional, Tuple
  import numpy
  import torch
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures.bbox import bbox_overlaps
  from mmdet.utils import ConfigType, InstanceList, OptConfigType, OptInstanceList
  from ..layers import multiclass_nms
  from ..utils import levels_to_images, multi_apply
  from .None 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, batch_gt_instances, batch_img_metas, batch_gt_instances_ignore, unmap_outputs) and returns: labels,  label_weights,  bbox_targets,  bbox_weights,  pos_inds,  gt_inds