class_docstr: DDQ auxiliary branches loss for dense queries.
  
  Args:
      loss_cls (dict):
          Configuration of classification loss function.
      loss_bbox (dict):
          Configuration of bbox regression loss function.
      train_cfg (dict):
          Configuration of gt targets assigner for each predicted bbox.
class_docstr_tok: ["DDQ","auxiliary","branches","loss","for","dense","queries",".","Args",":","loss_cls","(","dict",")",":","Configuration","of","classification","loss","function",".","loss_bbox","(","dict",")",":","Configuration","of","bbox","regression","loss","function",".","train_cfg","(","dict",")",":","Configuration","of","gt","targets","assigner","for","each","predicted","bbox","."]
docstr: Compute regression and classification targets for one image.
  
  Args:
      cls_scores (Tensor): Predicted normalized classification
          scores for one image, has shape (num_dense_queries,
          cls_out_channels).
      bbox_preds (Tensor): Predicted unnormalized bbox coordinates
          for one image, has shape (num_dense_queries, 4) with the
          last dimension arranged as (x1, y1, x2, y2).
      gt_bboxes (Tensor): Unnormalized ground truth
          bboxes for one image, has shape (num_gt, 4) with the
          last dimension arranged as (x1, y1, x2, y2).
          NOTE: num_gt is dynamic for each image.
      gt_labels (Tensor): Ground truth classification
              index for the image, has shape (num_gt,).
              NOTE: num_gt is dynamic for each image.
      img_meta (dict): Meta information for one image.
  
  Returns:
      tuple[Tensor]: a tuple containing the following for one image.
  
      - labels (Tensor): Labels for one image.
      - label_weights (Tensor): Label weights for one image.
      - bbox_targets (Tensor): Bbox targets for one image.
      - norm_alignment_metrics (Tensor): Normalized alignment
          metrics for one image.
docstr_tok: ["Compute","regression","and","classification","targets","for","one","image",".","Args",":","cls_scores","(","Tensor",")",":","Predicted","normalized","classification","scores","for","one","image",",","has","shape","(","num_dense_queries",",","cls_out_channels",")",".","bbox_preds","(","Tensor",")",":","Predicted","unnormalized","bbox","coordinates","for","one","image",",","has","shape","(","num_dense_queries",",","4",")","with","the","last","dimension","arranged","as","(","x1",",","y1",",","x2",",","y2",")",".","gt_bboxes","(","Tensor",")",":","Unnormalized","ground","truth","bboxes","for","one","image",",","has","shape","(","num_gt",",","4",")","with","the","last","dimension","arranged","as","(","x1",",","y1",",","x2",",","y2",")",".","NOTE",":","num_gt","is","dynamic","for","each","image",".","gt_labels","(","Tensor",")",":","Ground","truth","classification","index","for","the","image",",","has","shape","(","num_gt",",",")",".","NOTE",":","num_gt","is","dynamic","for","each","image",".","img_meta","(","dict",")",":","Meta","information","for","one","image",".","Returns",":","tuple","[","Tensor","]",":","a","tuple","containing","the","following","for","one","image",".","-","labels","(","Tensor",")",":","Labels","for","one","image",".","-","label_weights","(","Tensor",")",":","Label","weights","for","one","image",".","-","bbox_targets","(","Tensor",")",":","Bbox","targets","for","one","image",".","-","norm_alignment_metrics","(","Tensor",")",":","Normalized","alignment","metrics","for","one","image","."]
code: def _get_target_single(
      self,
      cls_scores,
      bbox_preds,
      gt_bboxes,
      gt_labels,
      img_meta,
      **kwargs,
  ):
      """Compute regression and classification targets for one image.
  
      Args:
          cls_scores (Tensor): Predicted normalized classification
              scores for one image, has shape (num_dense_queries,
              cls_out_channels).
          bbox_preds (Tensor): Predicted unnormalized bbox coordinates
              for one image, has shape (num_dense_queries, 4) with the
              last dimension arranged as (x1, y1, x2, y2).
          gt_bboxes (Tensor): Unnormalized ground truth
              bboxes for one image, has shape (num_gt, 4) with the
              last dimension arranged as (x1, y1, x2, y2).
              NOTE: num_gt is dynamic for each image.
          gt_labels (Tensor): Ground truth classification
                  index for the image, has shape (num_gt,).
                  NOTE: num_gt is dynamic for each image.
          img_meta (dict): Meta information for one image.
  
      Returns:
          tuple[Tensor]: a tuple containing the following for one image.
  
          - labels (Tensor): Labels for one image.
          - label_weights (Tensor): Label weights for one image.
          - bbox_targets (Tensor): Bbox targets for one image.
          - norm_alignment_metrics (Tensor): Normalized alignment
              metrics for one image.
      """
      if len(gt_labels) == 0:
          num_valid_anchors = len(cls_scores)
          bbox_targets = torch.zeros_like(bbox_preds)
          labels = bbox_preds.new_full(
              (num_valid_anchors,),
              cls_scores.size(-1),
              dtype=torch.long,
          )
          label_weights = bbox_preds.new_zeros(
              num_valid_anchors, dtype=torch.float
          )
          norm_alignment_metrics = bbox_preds.new_zeros(
              num_valid_anchors, dtype=torch.float
          )
          return (
              labels,
              label_weights,
              bbox_targets,
              norm_alignment_metrics,
          )
  
      assign_result = self.assigner.assign(
          cls_scores, bbox_preds, gt_bboxes, gt_labels, img_meta
      )
      assign_ious = assign_result.max_overlaps
      assign_metrics = assign_result.assign_metrics
  
      pred_instances = BaseDataElement()
      gt_instances = BaseDataElement()
  
      pred_instances.bboxes = bbox_preds
      gt_instances.bboxes = gt_bboxes
  
      pred_instances.priors = cls_scores
      gt_instances.labels = gt_labels
  
      sampling_result = self.sampler.sample(
          assign_result, pred_instances, gt_instances
      )
  
      num_valid_anchors = len(cls_scores)
      bbox_targets = torch.zeros_like(bbox_preds)
      labels = bbox_preds.new_full(
          (num_valid_anchors,), cls_scores.size(-1), dtype=torch.long
      )
      label_weights = bbox_preds.new_zeros(
          num_valid_anchors, dtype=torch.float
      )
      norm_alignment_metrics = bbox_preds.new_zeros(
          num_valid_anchors, dtype=torch.float
      )
  
      pos_inds = sampling_result.pos_inds
      neg_inds = sampling_result.neg_inds
      if len(pos_inds) > 0:
          # point-based
          pos_bbox_targets = sampling_result.pos_gt_bboxes
          bbox_targets[pos_inds, :] = pos_bbox_targets
  
          if gt_labels is None:
              # Only dense_heads gives gt_labels as None
              # Foreground is the first class since v2.5.0
              labels[pos_inds] = 0
          else:
              labels[pos_inds] = gt_labels[
                  sampling_result.pos_assigned_gt_inds
              ]
  
          label_weights[pos_inds] = 1.0
  
      if len(neg_inds) > 0:
          label_weights[neg_inds] = 1.0
  
      class_assigned_gt_inds = torch.unique(
          sampling_result.pos_assigned_gt_inds
      )
      for gt_inds in class_assigned_gt_inds:
          gt_class_inds = (
              sampling_result.pos_assigned_gt_inds == gt_inds
          )
          pos_alignment_metrics = assign_metrics[gt_class_inds]
          pos_ious = assign_ious[gt_class_inds]
          pos_norm_alignment_metrics = (
              pos_alignment_metrics
              / (pos_alignment_metrics.max() + 10e-8)
              * pos_ious.max()
          )
          norm_alignment_metrics[
              pos_inds[gt_class_inds]
          ] = pos_norm_alignment_metrics
  
      return (
          labels,
          label_weights,
          bbox_targets,
          norm_alignment_metrics,
      )
  
file_path: mmdetection/mmdet/models/losses/ddq_detr_aux_loss.py
imports: import torch
  import torch.nn
  from mmengine.structures import BaseDataElement
  from mmdet.models.utils import multi_apply
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.utils import reduce_mean
label_desc: Use image node_id 5 for calling the DDQAuxLoss obj's underlying member method code with example usage: obj._get_target_single(cls_scores, bbox_preds, gt_bboxes, gt_labels, img_meta) and returns: labels,  label_weights,  bbox_targets,  norm_alignment_metrics, labels,  label_weights,  bbox_targets,  norm_alignment_metrics