class_docstr: Head of DDQDETR: Dense Distinct Query for
      End-to-End Object Detection.
  
  Code is modified from the `official github repo
      <https://github.com/jshilong/DDQ>`_.
  
  More details can be found in the `paper
      <https://arxiv.org/abs/2303.12776>`_ .
  
  Args:
      aux_num_pos (int): Number of positive targets assigned to a
          perdicted object. Defaults to 4.
docstr: Forward function.
  
  Args:
      hidden_states (Tensor): Hidden states output from each decoder
          layer, has shape (num_decoder_layers, bs, num_queries_total,
          dim), where `num_queries_total` is the sum of
          `num_denoising_queries`, `num_queries` and `num_dense_queries`
          when `self.training` is `True`, else `num_queries`.
      references (list[Tensor]): List of the reference from the decoder.
          The first reference is the `init_reference` (initial) and the
          other num_decoder_layers(6) references are `inter_references`
          (intermediate). Each reference has shape (bs,
          num_queries_total, 4) with the last dimension arranged as
          (cx, cy, w, h).
  
  Returns:
      tuple[Tensor]: results of head containing the following tensors.
  
      - all_layers_outputs_classes (Tensor): Outputs from the
        classification head, has shape (num_decoder_layers, bs,
        num_queries_total, cls_out_channels).
      - all_layers_outputs_coords (Tensor): Sigmoid outputs from the
        regression head with normalized coordinate format (cx, cy, w,
        h), has shape (num_decoder_layers, bs, num_queries_total, 4)
        with the last dimension arranged as (cx, cy, w, h).
docstr_tok: ["Forward","function",".","Args",":","hidden_states","(","Tensor",")",":","Hidden","states","output","from","each","decoder","layer",",","has","shape","(","num_decoder_layers",",","bs",",","num_queries_total",",","dim",")",",","where","`","num_queries_total","`","is","the","sum","of","`","num_denoising_queries","`",",","`","num_queries","`","and","`","num_dense_queries","`","when","`","self.training","`","is","`","True","`",",","else","`","num_queries","`",".","references","(","list","[","Tensor","]",")",":","List","of","the","reference","from","the","decoder",".","The","first","reference","is","the","`","init_reference","`","(","initial",")","and","the","other","num_decoder_layers","(","6",")","references","are","`","inter_references","`","(","intermediate",")",".","Each","reference","has","shape","(","bs",",","num_queries_total",",","4",")","with","the","last","dimension","arranged","as","(","cx",",","cy",",","w",",","h",")",".","Returns",":","tuple","[","Tensor","]",":","results","of","head","containing","the","following","tensors",".","-","all_layers_outputs_classes","(","Tensor",")",":","Outputs","from","the","classification","head",",","has","shape","(","num_decoder_layers",",","bs",",","num_queries_total",",","cls_out_channels",")",".","-","all_layers_outputs_coords","(","Tensor",")",":","Sigmoid","outputs","from","the","regression","head","with","normalized","coordinate","format","(","cx",",","cy",",","w",",","h",")",",","has","shape","(","num_decoder_layers",",","bs",",","num_queries_total",",","4",")","with","the","last","dimension","arranged","as","(","cx",",","cy",",","w",",","h",")","."]
code: def forward(
      self, hidden_states: Tensor, references: List[Tensor]
  ) -> Tuple[Tensor]:
      """Forward function.
  
      Args:
          hidden_states (Tensor): Hidden states output from each decoder
              layer, has shape (num_decoder_layers, bs, num_queries_total,
              dim), where `num_queries_total` is the sum of
              `num_denoising_queries`, `num_queries` and `num_dense_queries`
              when `self.training` is `True`, else `num_queries`.
          references (list[Tensor]): List of the reference from the decoder.
              The first reference is the `init_reference` (initial) and the
              other num_decoder_layers(6) references are `inter_references`
              (intermediate). Each reference has shape (bs,
              num_queries_total, 4) with the last dimension arranged as
              (cx, cy, w, h).
  
      Returns:
          tuple[Tensor]: results of head containing the following tensors.
  
          - all_layers_outputs_classes (Tensor): Outputs from the
            classification head, has shape (num_decoder_layers, bs,
            num_queries_total, cls_out_channels).
          - all_layers_outputs_coords (Tensor): Sigmoid outputs from the
            regression head with normalized coordinate format (cx, cy, w,
            h), has shape (num_decoder_layers, bs, num_queries_total, 4)
            with the last dimension arranged as (cx, cy, w, h).
      """
      all_layers_outputs_classes = []
      all_layers_outputs_coords = []
      if self.training:
          num_dense = self.cache_dict["num_dense_queries"]
      for layer_id in range(hidden_states.shape[0]):
          reference = inverse_sigmoid(references[layer_id])
          hidden_state = hidden_states[layer_id]
          if self.training:
              dense_hidden_state = hidden_state[:, -num_dense:]
              hidden_state = hidden_state[:, :-num_dense]
  
          outputs_class = self.cls_branches[layer_id](hidden_state)
          tmp_reg_preds = self.reg_branches[layer_id](hidden_state)
          if self.training:
              dense_outputs_class = self.aux_cls_branches[layer_id](
                  dense_hidden_state
              )
              dense_tmp_reg_preds = self.aux_reg_branches[layer_id](
                  dense_hidden_state
              )
              outputs_class = torch.cat(
                  [outputs_class, dense_outputs_class], dim=1
              )
              tmp_reg_preds = torch.cat(
                  [tmp_reg_preds, dense_tmp_reg_preds], dim=1
              )
  
          if reference.shape[-1] == 4:
              tmp_reg_preds += reference
          else:
              assert reference.shape[-1] == 2
              tmp_reg_preds[..., :2] += reference
          outputs_coord = tmp_reg_preds.sigmoid()
          all_layers_outputs_classes.append(outputs_class)
          all_layers_outputs_coords.append(outputs_coord)
  
      all_layers_outputs_classes = torch.stack(
          all_layers_outputs_classes
      )
      all_layers_outputs_coords = torch.stack(all_layers_outputs_coords)
  
      return all_layers_outputs_classes, all_layers_outputs_coords
  
imports: import copy
  from typing import Dict, List, Tuple
  import torch
  from mmengine.model import bias_init_with_prob, constant_init
  from torch import Tensor, nn
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox_cxcywh_to_xyxy
  from mmdet.utils import InstanceList, OptInstanceList, reduce_mean
  from ..layers import inverse_sigmoid
  from ..losses import DDQAuxLoss
  from ..utils import multi_apply
  from .dino_head import DINOHead
label_desc: Use image node_id 4 for calling the DDQDETRHead obj's underlying member method code with example usage: obj.forward(hidden_states, references) and returns: all_layers_outputs_classes,  all_layers_outputs_coords