class_docstr: Head of DETR. DETR:End-to-End Object Detection with Transformers.
  
  More details can be found in the `paper
  <https://arxiv.org/pdf/2005.12872>`_ .
  
  Args:
      num_classes (int): Number of categories excluding the background.
      embed_dims (int): The dims of Transformer embedding.
      num_reg_fcs (int): Number of fully-connected layers used in `FFN`,
          which is then used for the regression head. Defaults to 2.
      sync_cls_avg_factor (bool): Whether to sync the `avg_factor` of
          all ranks. Default to `False`.
      loss_cls (:obj:`ConfigDict` or dict): Config of the classification
          loss. Defaults to `CrossEntropyLoss`.
      loss_bbox (:obj:`ConfigDict` or dict): Config of the regression bbox
          loss. Defaults to `L1Loss`.
      loss_iou (:obj:`ConfigDict` or dict): Config of the regression iou
          loss. Defaults to `GIoULoss`.
      train_cfg (:obj:`ConfigDict` or dict): Training config of transformer
          head.
      test_cfg (:obj:`ConfigDict` or dict): Testing config of transformer
          head.
      init_cfg (:obj:`ConfigDict` or dict, optional): the config to control
          the initialization. Defaults to None.
docstr: Compute regression and classification targets for a batch image.
  
  Outputs from a single decoder layer of a single feature level are used.
  
  Args:
      cls_scores_list (list[Tensor]): Box score logits from a single
          decoder layer for each image, has shape [num_queries,
          cls_out_channels].
      bbox_preds_list (list[Tensor]): Sigmoid outputs from a single
          decoder layer for each image, with normalized coordinate
          (cx, cy, w, h) and shape [num_queries, 4].
      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.
  
  Returns:
      tuple: a tuple containing the following targets.
  
      - labels_list (list[Tensor]): Labels for all images.
      - label_weights_list (list[Tensor]): Label weights for all images.
      - bbox_targets_list (list[Tensor]): BBox targets for all images.
      - bbox_weights_list (list[Tensor]): BBox weights for all images.
      - num_total_pos (int): Number of positive samples in all images.
      - num_total_neg (int): Number of negative samples in all images.
docstr_tok: ["Compute","regression","and","classification","targets","for","a","batch","image",".","Outputs","from","a","single","decoder","layer","of","a","single","feature","level","are","used",".","Args",":","cls_scores_list","(","list","[","Tensor","]",")",":","Box","score","logits","from","a","single","decoder","layer","for","each","image",",","has","shape","[","num_queries",",","cls_out_channels","]",".","bbox_preds_list","(","list","[","Tensor","]",")",":","Sigmoid","outputs","from","a","single","decoder","layer","for","each","image",",","with","normalized","coordinate","(","cx",",","cy",",","w",",","h",")","and","shape","[","num_queries",",","4","]",".","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",".","Returns",":","tuple",":","a","tuple","containing","the","following","targets",".","-","labels_list","(","list","[","Tensor","]",")",":","Labels","for","all","images",".","-","label_weights_list","(","list","[","Tensor","]",")",":","Label","weights","for","all","images",".","-","bbox_targets_list","(","list","[","Tensor","]",")",":","BBox","targets","for","all","images",".","-","bbox_weights_list","(","list","[","Tensor","]",")",":","BBox","weights","for","all","images",".","-","num_total_pos","(","int",")",":","Number","of","positive","samples","in","all","images",".","-","num_total_neg","(","int",")",":","Number","of","negative","samples","in","all","images","."]
code: def get_targets(
      self,
      cls_scores_list: List[Tensor],
      bbox_preds_list: List[Tensor],
      batch_gt_instances: InstanceList,
      batch_img_metas: List[dict],
  ) -> tuple:
      """Compute regression and classification targets for a batch image.
  
      Outputs from a single decoder layer of a single feature level are used.
  
      Args:
          cls_scores_list (list[Tensor]): Box score logits from a single
              decoder layer for each image, has shape [num_queries,
              cls_out_channels].
          bbox_preds_list (list[Tensor]): Sigmoid outputs from a single
              decoder layer for each image, with normalized coordinate
              (cx, cy, w, h) and shape [num_queries, 4].
          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.
  
      Returns:
          tuple: a tuple containing the following targets.
  
          - labels_list (list[Tensor]): Labels for all images.
          - label_weights_list (list[Tensor]): Label weights for all images.
          - bbox_targets_list (list[Tensor]): BBox targets for all images.
          - bbox_weights_list (list[Tensor]): BBox weights for all images.
          - num_total_pos (int): Number of positive samples in all images.
          - num_total_neg (int): Number of negative samples in all images.
      """
      (
          labels_list,
          label_weights_list,
          bbox_targets_list,
          bbox_weights_list,
          pos_inds_list,
          neg_inds_list,
      ) = multi_apply(
          self._get_targets_single,
          cls_scores_list,
          bbox_preds_list,
          batch_gt_instances,
          batch_img_metas,
      )
      num_total_pos = sum((inds.numel() for inds in pos_inds_list))
      num_total_neg = sum((inds.numel() for inds in neg_inds_list))
      return (
          labels_list,
          label_weights_list,
          bbox_targets_list,
          bbox_weights_list,
          num_total_pos,
          num_total_neg,
      )
  
imports: from typing import Dict, List, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import Linear
  from mmcv.cnn.bricks.transformer import FFN
  from mmengine.model import BaseModule
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox_cxcywh_to_xyxy, bbox_overlaps, bbox_xyxy_to_cxcywh
  from mmdet.utils import ConfigType, InstanceList, OptInstanceList, OptMultiConfig, reduce_mean
  from ..losses import QualityFocalLoss
  from ..utils import multi_apply
label_desc: Use image node_id 7 for calling the DETRHead obj's underlying member method code with example usage: obj.get_targets(cls_scores_list, bbox_preds_list, batch_gt_instances, batch_img_metas) and returns: labels_list,  label_weights_list,  bbox_targets_list,  bbox_weights_list,  num_total_pos,  num_total_neg