class_docstr: Head of DeformDETR: Deformable DETR: Deformable Transformers for
  End-to-End Object Detection.
  
  Code is modified from the `official github repo
  <https://github.com/fundamentalvision/Deformable-DETR>`_.
  
  More details can be found in the `paper
  <https://arxiv.org/abs/2010.04159>`_ .
  
  Args:
      share_pred_layer (bool): Whether to share parameters for all the
          prediction layers. Defaults to `False`.
      num_pred_layer (int): The number of the prediction layers.
          Defaults to 6.
      as_two_stage (bool, optional): Whether to generate the proposal
          from the outputs of encoder. Defaults to `False`.
docstr: Perform forward propagation and loss calculation of the detection
  head on the queries of the upstream network.
  
  Args:
      hidden_states (Tensor): Hidden states output from each decoder
          layer, has shape (num_decoder_layers, num_queries, bs, dim).
      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). The `init_reference` has shape (bs,
          num_queries, 4) when `as_two_stage` of the detector is `True`,
          otherwise (bs, num_queries, 2). Each `inter_reference` has
          shape (bs, num_queries, 4) when `with_box_refine` of the
          detector is `True`, otherwise (bs, num_queries, 2). The
          coordinates are arranged as (cx, cy) when the last dimension is
          2, and (cx, cy, w, h) when it is 4.
      enc_outputs_class (Tensor): The score of each point on encode
          feature map, has shape (bs, num_feat_points, cls_out_channels).
          Only when `as_two_stage` is `True` it would be passed in,
          otherwise it would be `None`.
      enc_outputs_coord (Tensor): The proposal generate from the encode
          feature map, has shape (bs, num_feat_points, 4) with the last
          dimension arranged as (cx, cy, w, h). Only when `as_two_stage`
          is `True` it would be passed in, otherwise it would be `None`.
      batch_data_samples (list[:obj:`DetDataSample`]): The Data
          Samples. It usually includes information such as
          `gt_instance`, `gt_panoptic_seg` and `gt_sem_seg`.
  
  Returns:
      dict: A dictionary of loss components.
docstr_tok: ["Perform","forward","propagation","and","loss","calculation","of","the","detection","head","on","the","queries","of","the","upstream","network",".","Args",":","hidden_states","(","Tensor",")",":","Hidden","states","output","from","each","decoder","layer",",","has","shape","(","num_decoder_layers",",","num_queries",",","bs",",","dim",")",".","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",")",".","The","`","init_reference","`","has","shape","(","bs",",","num_queries",",","4",")","when","`","as_two_stage","`","of","the","detector","is","`","True","`",",","otherwise","(","bs",",","num_queries",",","2",")",".","Each","`","inter_reference","`","has","shape","(","bs",",","num_queries",",","4",")","when","`","with_box_refine","`","of","the","detector","is","`","True","`",",","otherwise","(","bs",",","num_queries",",","2",")",".","The","coordinates","are","arranged","as","(","cx",",","cy",")","when","the","last","dimension","is","2",",","and","(","cx",",","cy",",","w",",","h",")","when","it","is","4.","enc_outputs_class","(","Tensor",")",":","The","score","of","each","point","on","encode","feature","map",",","has","shape","(","bs",",","num_feat_points",",","cls_out_channels",")",".","Only","when","`","as_two_stage","`","is","`","True","`","it","would","be","passed","in",",","otherwise","it","would","be","`","None","`",".","enc_outputs_coord","(","Tensor",")",":","The","proposal","generate","from","the","encode","feature","map",",","has","shape","(","bs",",","num_feat_points",",","4",")","with","the","last","dimension","arranged","as","(","cx",",","cy",",","w",",","h",")",".","Only","when","`","as_two_stage","`","is","`","True","`","it","would","be","passed","in",",","otherwise","it","would","be","`","None","`",".","batch_data_samples","(","list","[",":","obj",":","`","DetDataSample","`","]",")",":","The","Data","Samples",".","It","usually","includes","information","such","as","`","gt_instance","`",",","`","gt_panoptic_seg","`","and","`","gt_sem_seg","`",".","Returns",":","dict",":","A","dictionary","of","loss","components","."]
code: def loss(
      self,
      hidden_states: Tensor,
      references: List[Tensor],
      enc_outputs_class: Tensor,
      enc_outputs_coord: Tensor,
      batch_data_samples: SampleList,
  ) -> dict:
      """Perform forward propagation and loss calculation of the detection
      head on the queries of the upstream network.
  
      Args:
          hidden_states (Tensor): Hidden states output from each decoder
              layer, has shape (num_decoder_layers, num_queries, bs, dim).
          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). The `init_reference` has shape (bs,
              num_queries, 4) when `as_two_stage` of the detector is `True`,
              otherwise (bs, num_queries, 2). Each `inter_reference` has
              shape (bs, num_queries, 4) when `with_box_refine` of the
              detector is `True`, otherwise (bs, num_queries, 2). The
              coordinates are arranged as (cx, cy) when the last dimension is
              2, and (cx, cy, w, h) when it is 4.
          enc_outputs_class (Tensor): The score of each point on encode
              feature map, has shape (bs, num_feat_points, cls_out_channels).
              Only when `as_two_stage` is `True` it would be passed in,
              otherwise it would be `None`.
          enc_outputs_coord (Tensor): The proposal generate from the encode
              feature map, has shape (bs, num_feat_points, 4) with the last
              dimension arranged as (cx, cy, w, h). Only when `as_two_stage`
              is `True` it would be passed in, otherwise it would be `None`.
          batch_data_samples (list[:obj:`DetDataSample`]): The Data
              Samples. It usually includes information such as
              `gt_instance`, `gt_panoptic_seg` and `gt_sem_seg`.
  
      Returns:
          dict: A dictionary of loss components.
      """
      batch_gt_instances = []
      batch_img_metas = []
      for data_sample in batch_data_samples:
          batch_img_metas.append(data_sample.metainfo)
          batch_gt_instances.append(data_sample.gt_instances)
  
      outs = self(hidden_states, references)
      loss_inputs = outs + (
          enc_outputs_class,
          enc_outputs_coord,
          batch_gt_instances,
          batch_img_metas,
      )
      losses = self.loss_by_feat(*loss_inputs)
      return losses
  
imports: import copy
  from typing import Dict, List, Tuple
  import torch
  import torch.nn
  from mmcv.cnn import Linear
  from mmengine.model import bias_init_with_prob, constant_init
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.utils import InstanceList, OptInstanceList
  from ..layers import inverse_sigmoid
  from .detr_head import DETRHead
label_desc: Use image node_id 5 for calling the DeformableDETRHead obj's underlying member method code with example usage: obj.loss(hidden_states, references, enc_outputs_class, enc_outputs_coord, batch_data_samples) and returns: losses