class_docstr: Head of the Align-DETR: Improving DETR with Simple IoU-aware BCE loss
  
  Code is modified from the `official github repo
  <https://github.com/FelixCaae/AlignDETR>`_.
  
  More details can be found in the `paper
  <https://arxiv.org/abs/2304.07527>`_ .
  
  Args:
      all_layers_num_gt_repeat List[int]: Number to repeat gt for 1-to-k
          matching between ground truth and predictions of each decoder
          layer. Only used for matching queries, not for denoising queries.
          Element count is `num_pred_layer`. If `as_two_stage` is True, then
          the last element is for encoder output, and the others for
          decoder layers. Otherwise, all elements are for decoder layers.
          Defaults to a list of `1` for the last decoder layer and `2` for
          the others.
      alpha (float): Hyper-parameter of classification loss that controls
          the proportion of each item to calculate `t`, the weighted
          geometric average of the confident score and the IoU score, to
          align classification and regression scores. Defaults to `0.25`.
      gamma (float): Hyper-parameter of classification loss to do the hard
          negative mining. Defaults to `2.0`.
      tau (float): Hyper-parameter of classification and regression losses,
          it is the temperature controlling the sharpness of the function
          to calculate positive sample weight. Defaults to `1.5`.
class_docstr_tok: ["Head","of","the","Align-DETR",":","Improving","DETR","with","Simple","IoU-aware","BCE","loss","Code","is","modified","from","the","`","official","github","repo","<","https",":","\/\/github.com\/FelixCaae\/AlignDETR",">","`","_",".","More","details","can","be","found","in","the","`","paper","<","https",":","\/\/arxiv.org\/abs\/2304.07527",">","`","_",".","Args",":","all_layers_num_gt_repeat","List","[","int","]",":","Number","to","repeat","gt","for","1-to-k","matching","between","ground","truth","and","predictions","of","each","decoder","layer",".","Only","used","for","matching","queries",",","not","for","denoising","queries",".","Element","count","is","`","num_pred_layer","`",".","If","`","as_two_stage","`","is","True",",","then","the","last","element","is","for","encoder","output",",","and","the","others","for","decoder","layers",".","Otherwise",",","all","elements","are","for","decoder","layers",".","Defaults","to","a","list","of","`","1","`","for","the","last","decoder","layer","and","`","2","`","for","the","others",".","alpha","(","float",")",":","Hyper-parameter","of","classification","loss","that","controls","the","proportion","of","each","item","to","calculate","`","t","`",",","the","weighted","geometric","average","of","the","confident","score","and","the","IoU","score",",","to","align","classification","and","regression","scores",".","Defaults","to","`","0.25","`",".","gamma","(","float",")",":","Hyper-parameter","of","classification","loss","to","do","the","hard","negative","mining",".","Defaults","to","`","2.0","`",".","tau","(","float",")",":","Hyper-parameter","of","classification","and","regression","losses",",","it","is","the","temperature","controlling","the","sharpness","of","the","function","to","calculate","positive","sample","weight",".","Defaults","to","`","1.5","`","."]
docstr: Compute regression and classification targets for a batch image.
  
  Outputs from a single decoder layer of a single feature level are used.
  AlignDETR: This method is based on `DETRHead.get_targets`.
  
  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",".","AlignDETR",":","This","method","is","based","on","`","DETRHead.get_targets","`",".","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.
      AlignDETR: This method is based on `DETRHead.get_targets`.
  
      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.
      """
      results = super(AlignDETRHead, self).get_targets(
          cls_scores_list,
          bbox_preds_list,
          batch_gt_instances,
          batch_img_metas,
      )
  
      # AlignDETR: `num_total_pos` for matching queries is the number of
      #   unique gt bboxes in the batch. Refer to AlignDETR official code:
      #   https://github.com/FelixCaae/AlignDETR/blob/8c2b1806026e1b33fe1c282577de1647e352d7f0/aligndetr/criterions/base_criterion.py#L195C15-L195C15  # noqa: E501
      num_total_pos = sum(
          len(gt_instances) for gt_instances in batch_gt_instances
      )
  
      results = list(results)
      results[-2] = num_total_pos
      return tuple(results)
  
file_path: mmdetection/projects/AlignDETR/align_detr/align_detr_head.py
imports: from typing import Any, Dict, List, Tuple, Union
  import torch
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.models.dense_heads import DINOHead
  from mmdet.registry import MODELS
  from mmdet.structures.bbox import bbox_cxcywh_to_xyxy, bbox_overlaps, bbox_xyxy_to_cxcywh
  from mmdet.utils import InstanceList
  from .utils import KeysRecorder
label_desc: Use image node_id 4 for calling the AlignDETRHead 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: tuple