class_docstr: Anchor-based head (RPN, RetinaNet, SSD, etc.).
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      feat_channels (int): Number of hidden channels. Used in child classes.
      anchor_generator (dict): Config dict for anchor generator
      bbox_coder (dict): Config of bounding box coder.
      reg_decoded_bbox (bool): If true, the regression loss would be
          applied directly on decoded bounding boxes, converting both
          the predicted boxes and regression targets to absolute
          coordinates format. Default False. It should be `True` when
          using `IoULoss`, `GIoULoss`, or `DIoULoss` in the bbox head.
      loss_cls (dict): Config of classification loss.
      loss_bbox (dict): Config of localization loss.
      train_cfg (dict): Training config of anchor head.
      test_cfg (dict): Testing config of anchor head.
      init_cfg (dict or list[dict], optional): Initialization config dict.
class_docstr_tok: ["Anchor-based","head","(","RPN",",","RetinaNet",",","SSD",",","etc.",")",".","Args",":","num_classes","(","int",")",":","Number","of","categories","excluding","the","background","category",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","feat_channels","(","int",")",":","Number","of","hidden","channels",".","Used","in","child","classes",".","anchor_generator","(","dict",")",":","Config","dict","for","anchor","generator","bbox_coder","(","dict",")",":","Config","of","bounding","box","coder",".","reg_decoded_bbox","(","bool",")",":","If","true",",","the","regression","loss","would","be","applied","directly","on","decoded","bounding","boxes",",","converting","both","the","predicted","boxes","and","regression","targets","to","absolute","coordinates","format",".","Default","False",".","It","should","be","`","True","`","when","using","`","IoULoss","`",",","`","GIoULoss","`",",","or","`","DIoULoss","`","in","the","bbox","head",".","loss_cls","(","dict",")",":","Config","of","classification","loss",".","loss_bbox","(","dict",")",":","Config","of","localization","loss",".","train_cfg","(","dict",")",":","Training","config","of","anchor","head",".","test_cfg","(","dict",")",":","Testing","config","of","anchor","head",".","init_cfg","(","dict","or","list","[","dict","]",",","optional",")",":","Initialization","config","dict","."]
docstr: Compute regression and classification targets for anchors in
  multiple images.
  
  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.
      return_sampling_results (bool): Whether to return the sampling
          results. Defaults to False.
  
  Returns:
      tuple: Usually returns a tuple containing learning targets.
  
          - labels_list (list[Tensor]): Labels of each level.
          - label_weights_list (list[Tensor]): Label weights of each
            level.
          - bbox_targets_list (list[Tensor]): BBox targets of each level.
          - bbox_weights_list (list[Tensor]): BBox weights of each level.
          - avg_factor (int): Average factor that is used to average
            the loss. When using sampling method, avg_factor is usually
            the sum of positive and negative priors. When using
            `PseudoSampler`, `avg_factor` is usually equal to the number
            of positive priors.
  
      additional_returns: This function enables user-defined returns from
          `self._get_targets_single`. These returns are currently refined
          to properties at each feature map (i.e. having HxW dimension).
          The results will be concatenated after the end
docstr_tok: ["Compute","regression","and","classification","targets","for","anchors","in","multiple","images",".","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",".","return_sampling_results","(","bool",")",":","Whether","to","return","the","sampling","results",".","Defaults","to","False",".","Returns",":","tuple",":","Usually","returns","a","tuple","containing","learning","targets",".","-","labels_list","(","list","[","Tensor","]",")",":","Labels","of","each","level",".","-","label_weights_list","(","list","[","Tensor","]",")",":","Label","weights","of","each","level",".","-","bbox_targets_list","(","list","[","Tensor","]",")",":","BBox","targets","of","each","level",".","-","bbox_weights_list","(","list","[","Tensor","]",")",":","BBox","weights","of","each","level",".","-","avg_factor","(","int",")",":","Average","factor","that","is","used","to","average","the","loss",".","When","using","sampling","method",",","avg_factor","is","usually","the","sum","of","positive","and","negative","priors",".","When","using","`","PseudoSampler","`",",","`","avg_factor","`","is","usually","equal","to","the","number","of","positive","priors",".","additional_returns",":","This","function","enables","user-defined","returns","from","`","self._get_targets_single","`",".","These","returns","are","currently","refined","to","properties","at","each","feature","map","(","i.e",".","having","HxW","dimension",")",".","The","results","will","be","concatenated","after","the","end"]
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,
      return_sampling_results: bool = False,
  ) -> tuple:
      """Compute regression and classification targets for anchors in
      multiple images.
  
      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.
          return_sampling_results (bool): Whether to return the sampling
              results. Defaults to False.
  
      Returns:
          tuple: Usually returns a tuple containing learning targets.
  
              - labels_list (list[Tensor]): Labels of each level.
              - label_weights_list (list[Tensor]): Label weights of each
                level.
              - bbox_targets_list (list[Tensor]): BBox targets of each level.
              - bbox_weights_list (list[Tensor]): BBox weights of each level.
              - avg_factor (int): Average factor that is used to average
                the loss. When using sampling method, avg_factor is usually
                the sum of positive and negative priors. When using
                `PseudoSampler`, `avg_factor` is usually equal to the number
                of positive priors.
  
          additional_returns: This function enables user-defined returns from
              `self._get_targets_single`. These returns are currently refined
              to properties at each feature map (i.e. having HxW dimension).
              The results will be concatenated after the end
      """
      num_imgs = len(batch_img_metas)
      assert len(anchor_list) == len(valid_flag_list) == num_imgs
  
      if batch_gt_instances_ignore is None:
          batch_gt_instances_ignore = [None] * num_imgs
  
      # anchor number of multi levels
      num_level_anchors = [
          anchors.size(0) for anchors in anchor_list[0]
      ]
      # concat all level anchors to a single tensor
      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(cat_boxes(anchor_list[i]))
          concat_valid_flag_list.append(torch.cat(valid_flag_list[i]))
  
      # compute targets for each image
      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,
      )
      (
          all_labels,
          all_label_weights,
          all_bbox_targets,
          all_bbox_weights,
          pos_inds_list,
          neg_inds_list,
          sampling_results_list,
      ) = results[:7]
      rest_results = list(results[7:])  # user-added return values
      # Get `avg_factor` of all images, which calculate in `SamplingResult`.
      # When using sampling method, avg_factor is usually the sum of
      # positive and negative priors. When using `PseudoSampler`,
      # `avg_factor` is usually equal to the number of positive priors.
      avg_factor = sum(
          [results.avg_factor for results in sampling_results_list]
      )
      # update `_raw_positive_infos`, which will be used when calling
      # `get_positive_infos`.
      self._raw_positive_infos.update(
          sampling_results=sampling_results_list
      )
      # split targets to a list w.r.t. multiple levels
      labels_list = images_to_levels(all_labels, num_level_anchors)
      label_weights_list = images_to_levels(
          all_label_weights, num_level_anchors
      )
      bbox_targets_list = images_to_levels(
          all_bbox_targets, num_level_anchors
      )
      bbox_weights_list = images_to_levels(
          all_bbox_weights, num_level_anchors
      )
      res = (
          labels_list,
          label_weights_list,
          bbox_targets_list,
          bbox_weights_list,
          avg_factor,
      )
      if return_sampling_results:
          res = res + (sampling_results_list,)
      for i, r in enumerate(rest_results):  # user-added return values
          rest_results[i] = images_to_levels(r, num_level_anchors)
  
      return res + tuple(rest_results)
  
imports: import warnings
  from typing import List, Optional, Tuple, Union
  import torch
  import torch.nn
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures.bbox import BaseBoxes, cat_boxes, get_box_tensor
  from mmdet.utils import ConfigType, InstanceList, OptConfigType, OptInstanceList, OptMultiConfig
  from ..task_modules.prior_generators import AnchorGenerator, anchor_inside_flags
  from ..task_modules.samplers import PseudoSampler
  from ..utils import images_to_levels, multi_apply, unmap
  from .base_dense_head import BaseDenseHead
label_desc: Use image node_id 9 for calling the AnchorHead 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, return_sampling_results) and returns: unknown