class_docstr: Detection Head of RTMDet.
  
  Args:
      num_classes (int): Number of categories excluding the background
          category.
      in_channels (int): Number of channels in the input feature map.
      with_objectness (bool): Whether to add an objectness branch.
          Defaults to True.
      act_cfg (:obj:`ConfigDict` or dict): Config dict for activation layer.
          Default: dict(type='ReLU')
class_docstr_tok: ["Detection","Head","of","RTMDet",".","Args",":","num_classes","(","int",")",":","Number","of","categories","excluding","the","background","category",".","in_channels","(","int",")",":","Number","of","channels","in","the","input","feature","map",".","with_objectness","(","bool",")",":","Whether","to","add","an","objectness","branch",".","Defaults","to","True",".","act_cfg","(",":","obj",":","`","ConfigDict","`","or","dict",")",":","Config","dict","for","activation","layer",".","Default",":","dict","(","type='ReLU","'",")"]
docstr: Compute regression and classification targets for anchors in
  multiple images.
  
  Args:
      cls_scores (Tensor): Classification predictions of images,
          a 3D-Tensor with shape [num_imgs, num_priors, num_classes].
      bbox_preds (Tensor): Decoded bboxes predictions of one image,
          a 3D-Tensor with shape [num_imgs, num_priors, 4] in [tl_x,
          tl_y, br_x, br_y] format.
      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: a tuple containing learning targets.
  
      - anchors_list (list[list[Tensor]]): Anchors of each level.
      - 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.
      - assign_metrics_list (list[Tensor]): alignment metrics of each
        level.
docstr_tok: ["Compute","regression","and","classification","targets","for","anchors","in","multiple","images",".","Args",":","cls_scores","(","Tensor",")",":","Classification","predictions","of","images",",","a","3D-Tensor","with","shape","[","num_imgs",",","num_priors",",","num_classes","]",".","bbox_preds","(","Tensor",")",":","Decoded","bboxes","predictions","of","one","image",",","a","3D-Tensor","with","shape","[","num_imgs",",","num_priors",",","4","]","in","[","tl_x",",","tl_y",",","br_x",",","br_y","]","format",".","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",":","a","tuple","containing","learning","targets",".","-","anchors_list","(","list","[","list","[","Tensor","]","]",")",":","Anchors","of","each","level",".","-","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",".","-","assign_metrics_list","(","list","[","Tensor","]",")",":","alignment","metrics","of","each","level","."]
code: def get_targets(
      self,
      cls_scores: Tensor,
      bbox_preds: Tensor,
      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=True,
  ):
      """Compute regression and classification targets for anchors in
      multiple images.
  
      Args:
          cls_scores (Tensor): Classification predictions of images,
              a 3D-Tensor with shape [num_imgs, num_priors, num_classes].
          bbox_preds (Tensor): Decoded bboxes predictions of one image,
              a 3D-Tensor with shape [num_imgs, num_priors, 4] in [tl_x,
              tl_y, br_x, br_y] format.
          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: a tuple containing learning targets.
  
          - anchors_list (list[list[Tensor]]): Anchors of each level.
          - 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.
          - assign_metrics_list (list[Tensor]): alignment metrics of each
            level.
      """
      num_imgs = len(batch_img_metas)
      assert len(anchor_list) == len(valid_flag_list) == num_imgs
  
      # anchor number of multi levels
      num_level_anchors = [
          anchors.size(0) for anchors in anchor_list[0]
      ]
  
      # concat all level anchors and flags to a single tensor
      for i in range(num_imgs):
          assert len(anchor_list[i]) == len(valid_flag_list[i])
          anchor_list[i] = torch.cat(anchor_list[i])
          valid_flag_list[i] = 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
      # anchor_list: list(b * [-1, 4])
      (
          all_anchors,
          all_labels,
          all_label_weights,
          all_bbox_targets,
          all_assign_metrics,
          sampling_results_list,
      ) = multi_apply(
          self._get_targets_single,
          cls_scores.detach(),
          bbox_preds.detach(),
          anchor_list,
          valid_flag_list,
          batch_gt_instances,
          batch_img_metas,
          batch_gt_instances_ignore,
          unmap_outputs=unmap_outputs,
      )
      # no valid anchors
      if any([labels is None for labels in all_labels]):
          return None
  
      # split targets to a list w.r.t. multiple levels
      anchors_list = images_to_levels(all_anchors, num_level_anchors)
      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
      )
      assign_metrics_list = images_to_levels(
          all_assign_metrics, num_level_anchors
      )
  
      return (
          anchors_list,
          labels_list,
          label_weights_list,
          bbox_targets_list,
          assign_metrics_list,
          sampling_results_list,
      )
  
imports: from typing import List, Optional, Tuple, Union
  import torch
  import torch.nn
  from mmcv.cnn import ConvModule, DepthwiseSeparableConvModule, Scale, is_norm
  from mmengine.model import bias_init_with_prob, constant_init, normal_init
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures.bbox import distance2bbox
  from mmdet.utils import ConfigType, InstanceList, OptInstanceList, reduce_mean
  from ..layers.transformer import inverse_sigmoid
  from ..task_modules import anchor_inside_flags
  from ..utils import images_to_levels, multi_apply, sigmoid_geometric_mean, unmap
  from .atss_head import ATSSHead
label_desc: Use image node_id 7 for calling the RTMDetHead obj's underlying member method code with example usage: obj.get_targets(cls_scores, bbox_preds, anchor_list, valid_flag_list, batch_gt_instances, batch_img_metas, batch_gt_instances_ignore, unmap_outputs) and returns: anchors_list,  labels_list,  label_weights_list,  bbox_targets_list,  assign_metrics_list,  sampling_results_list, None