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: Calculate auxiliary branches loss for dense queries for one image.
  
  Args:
      cls_score (Tensor): Predicted normalized classification
          scores for one image, has shape (num_dense_queries,
          cls_out_channels).
      bbox_pred (Tensor): Predicted unnormalized bbox coordinates
          for one image, has shape (num_dense_queries, 4) with the
          last dimension arranged as (x1, y1, x2, y2).
      labels (Tensor): Labels for one image.
      label_weights (Tensor): Label weights for one image.
      bbox_targets (Tensor): Bbox targets for one image.
      alignment_metrics (Tensor): Normalized alignment metrics for one
          image.
  
  Returns:
      tuple: A tuple of loss components and loss weights.
docstr_tok: ["Calculate","auxiliary","branches","loss","for","dense","queries","for","one","image",".","Args",":","cls_score","(","Tensor",")",":","Predicted","normalized","classification","scores","for","one","image",",","has","shape","(","num_dense_queries",",","cls_out_channels",")",".","bbox_pred","(","Tensor",")",":","Predicted","unnormalized","bbox","coordinates","for","one","image",",","has","shape","(","num_dense_queries",",","4",")","with","the","last","dimension","arranged","as","(","x1",",","y1",",","x2",",","y2",")",".","labels","(","Tensor",")",":","Labels","for","one","image",".","label_weights","(","Tensor",")",":","Label","weights","for","one","image",".","bbox_targets","(","Tensor",")",":","Bbox","targets","for","one","image",".","alignment_metrics","(","Tensor",")",":","Normalized","alignment","metrics","for","one","image",".","Returns",":","tuple",":","A","tuple","of","loss","components","and","loss","weights","."]
code: def loss_single(
      self,
      cls_score,
      bbox_pred,
      labels,
      label_weights,
      bbox_targets,
      alignment_metrics,
  ):
      """Calculate auxiliary branches loss for dense queries for one image.
  
      Args:
          cls_score (Tensor): Predicted normalized classification
              scores for one image, has shape (num_dense_queries,
              cls_out_channels).
          bbox_pred (Tensor): Predicted unnormalized bbox coordinates
              for one image, has shape (num_dense_queries, 4) with the
              last dimension arranged as (x1, y1, x2, y2).
          labels (Tensor): Labels for one image.
          label_weights (Tensor): Label weights for one image.
          bbox_targets (Tensor): Bbox targets for one image.
          alignment_metrics (Tensor): Normalized alignment metrics for one
              image.
  
      Returns:
          tuple: A tuple of loss components and loss weights.
      """
      bbox_targets = bbox_targets.reshape(-1, 4)
      labels = labels.reshape(-1)
      alignment_metrics = alignment_metrics.reshape(-1)
      label_weights = label_weights.reshape(-1)
      targets = (labels, alignment_metrics)
      cls_loss_func = self.loss_cls
  
      loss_cls = cls_loss_func(
          cls_score, targets, label_weights, avg_factor=1.0
      )
  
      # FG cat_id: [0, num_classes -1], BG cat_id: num_classes
      bg_class_ind = cls_score.size(-1)
      pos_inds = (
          ((labels >= 0) & (labels < bg_class_ind)).nonzero().squeeze(1)
      )
  
      if len(pos_inds) > 0:
          pos_bbox_targets = bbox_targets[pos_inds]
          pos_bbox_pred = bbox_pred[pos_inds]
  
          pos_decode_bbox_pred = pos_bbox_pred
          pos_decode_bbox_targets = pos_bbox_targets
  
          # regression loss
          pos_bbox_weight = alignment_metrics[pos_inds]
  
          loss_bbox = self.loss_bbox(
              pos_decode_bbox_pred,
              pos_decode_bbox_targets,
              weight=pos_bbox_weight,
              avg_factor=1.0,
          )
      else:
          loss_bbox = bbox_pred.sum() * 0
          pos_bbox_weight = bbox_targets.new_tensor(0.0)
  
      return (
          loss_cls,
          loss_bbox,
          alignment_metrics.sum(),
          pos_bbox_weight.sum(),
      )
  
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 2 for calling the DDQAuxLoss obj's underlying member method code with example usage: obj.loss_single(cls_score, bbox_pred, labels, label_weights, bbox_targets, alignment_metrics) and returns: loss_cls,  loss_bbox,  alignment_metrics,  pos_bbox_weight