class_docstr: Head of Conditional DETR. Conditional DETR: Conditional DETR for Fast
  Training Convergence. More details can be found in the `paper.
  
  <https://arxiv.org/abs/2108.06152>`_ .
class_docstr_tok: ["Head","of","Conditional","DETR",".","Conditional","DETR",":","Conditional","DETR","for","Fast","Training","Convergence",".","More","details","can","be","found","in","the","`","paper",".","<","https",":","\/\/arxiv.org\/abs\/2108.06152",">","`","_","."]
docstr: "Forward function.
  
  Args:
      hidden_states (Tensor): Features from transformer decoder. If
          `return_intermediate_dec` is True output has shape
          (num_decoder_layers, bs, num_queries, dim), else has shape (1,
          bs, num_queries, dim) which only contains the last layer
          outputs.
      references (Tensor): References from transformer decoder, has
          shape (bs, num_queries, 2).
  Returns:
      tuple[Tensor]: results of head containing the following tensor.
  
      - layers_cls_scores (Tensor): Outputs from the classification head,
        shape (num_decoder_layers, bs, num_queries, cls_out_channels).
        Note cls_out_channels should include background.
      - layers_bbox_preds (Tensor): Sigmoid outputs from the regression
        head with normalized coordinate format (cx, cy, w, h), has shape
        (num_decoder_layers, bs, num_queries, 4).
docstr_tok: ["``","Forward","function",".","Args",":","hidden_states","(","Tensor",")",":","Features","from","transformer","decoder",".","If","`","return_intermediate_dec","`","is","True","output","has","shape","(","num_decoder_layers",",","bs",",","num_queries",",","dim",")",",","else","has","shape","(","1",",","bs",",","num_queries",",","dim",")","which","only","contains","the","last","layer","outputs",".","references","(","Tensor",")",":","References","from","transformer","decoder",",","has","shape","(","bs",",","num_queries",",","2",")",".","Returns",":","tuple","[","Tensor","]",":","results","of","head","containing","the","following","tensor",".","-","layers_cls_scores","(","Tensor",")",":","Outputs","from","the","classification","head",",","shape","(","num_decoder_layers",",","bs",",","num_queries",",","cls_out_channels",")",".","Note","cls_out_channels","should","include","background",".","-","layers_bbox_preds","(","Tensor",")",":","Sigmoid","outputs","from","the","regression","head","with","normalized","coordinate","format","(","cx",",","cy",",","w",",","h",")",",","has","shape","(","num_decoder_layers",",","bs",",","num_queries",",","4",")","."]
code: def forward(
      self, hidden_states: Tensor, references: Tensor
  ) -> Tuple[Tensor, Tensor]:
      """ "Forward function.
  
      Args:
          hidden_states (Tensor): Features from transformer decoder. If
              `return_intermediate_dec` is True output has shape
              (num_decoder_layers, bs, num_queries, dim), else has shape (1,
              bs, num_queries, dim) which only contains the last layer
              outputs.
          references (Tensor): References from transformer decoder, has
              shape (bs, num_queries, 2).
      Returns:
          tuple[Tensor]: results of head containing the following tensor.
  
          - layers_cls_scores (Tensor): Outputs from the classification head,
            shape (num_decoder_layers, bs, num_queries, cls_out_channels).
            Note cls_out_channels should include background.
          - layers_bbox_preds (Tensor): Sigmoid outputs from the regression
            head with normalized coordinate format (cx, cy, w, h), has shape
            (num_decoder_layers, bs, num_queries, 4).
      """
  
      references_unsigmoid = inverse_sigmoid(references)
      layers_bbox_preds = []
      for layer_id in range(hidden_states.shape[0]):
          tmp_reg_preds = self.fc_reg(
              self.activate(self.reg_ffn(hidden_states[layer_id]))
          )
          tmp_reg_preds[..., :2] += references_unsigmoid
          outputs_coord = tmp_reg_preds.sigmoid()
          layers_bbox_preds.append(outputs_coord)
      layers_bbox_preds = torch.stack(layers_bbox_preds)
  
      layers_cls_scores = self.fc_cls(hidden_states)
      return layers_cls_scores, layers_bbox_preds
  
file_path: mmdetection/mmdet/models/dense_heads/conditional_detr_head.py
imports: from typing import Tuple
  import torch
  import torch.nn
  from mmengine.model import bias_init_with_prob
  from torch import Tensor
  from mmdet.models.layers.transformer import inverse_sigmoid
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.utils import InstanceList
  from .detr_head import DETRHead
label_desc: Use image node_id 2 for calling the ConditionalDETRHead obj's underlying member method code with example usage: obj.forward(hidden_states, references) and returns: layers_cls_scores,  layers_bbox_preds