class_docstr: Head of the DINO: DETR with Improved DeNoising Anchor Boxes
  for End-to-End Object Detection
  
  Code is modified from the `official github repo
  <https://github.com/IDEA-Research/DINO>`_.
  
  More details can be found in the `paper
  <https://arxiv.org/abs/2203.03605>`_ .
class_docstr_tok: ["Head","of","the","DINO",":","DETR","with","Improved","DeNoising","Anchor","Boxes","for","End-to-End","Object","Detection","Code","is","modified","from","the","`","official","github","repo","<","https",":","\/\/github.com\/IDEA-Research\/DINO",">","`","_",".","More","details","can","be","found","in","the","`","paper","<","https",":","\/\/arxiv.org\/abs\/2203.03605",">","`","_","."]
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, bs, num_queries_total,
          dim), where `num_queries_total` is the sum of
          `num_denoising_queries` and `num_matching_queries` when
          `self.training` is `True`, else `num_matching_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). The `init_reference` has shape (bs,
          num_queries_total, 4) and each `inter_reference` has shape
          (bs, num_queries, 4) with the last dimension arranged as
          (cx, cy, w, h).
      enc_outputs_class (Tensor): The score of each point on encode
          feature map, has shape (bs, num_feat_points, cls_out_channels).
      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).
      batch_data_samples (list[:obj:`DetDataSample`]): The Data
          Samples. It usually includes information such as
          `gt_instance`, `gt_panoptic_seg` and `gt_sem_seg`.
      dn_meta (Dict[str, int]): The dictionary saves information about
        group collation, including 'num_denoising_queries' and
        'num_denoising_groups'. It will be used for split outputs of
        denoising and matching parts and loss calculation.
  
  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",",","bs",",","num_queries_total",",","dim",")",",","where","`","num_queries_total","`","is","the","sum","of","`","num_denoising_queries","`","and","`","num_matching_queries","`","when","`","self.training","`","is","`","True","`",",","else","`","num_matching_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",")",".","The","`","init_reference","`","has","shape","(","bs",",","num_queries_total",",","4",")","and","each","`","inter_reference","`","has","shape","(","bs",",","num_queries",",","4",")","with","the","last","dimension","arranged","as","(","cx",",","cy",",","w",",","h",")",".","enc_outputs_class","(","Tensor",")",":","The","score","of","each","point","on","encode","feature","map",",","has","shape","(","bs",",","num_feat_points",",","cls_out_channels",")",".","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",")",".","batch_data_samples","(","list","[",":","obj",":","`","DetDataSample","`","]",")",":","The","Data","Samples",".","It","usually","includes","information","such","as","`","gt_instance","`",",","`","gt_panoptic_seg","`","and","`","gt_sem_seg","`",".","dn_meta","(","Dict","[","str",",","int","]",")",":","The","dictionary","saves","information","about","group","collation",",","including","'num_denoising_queries","'","and","'num_denoising_groups","'",".","It","will","be","used","for","split","outputs","of","denoising","and","matching","parts","and","loss","calculation",".","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,
      dn_meta: Dict[str, int],
  ) -> 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, bs, num_queries_total,
              dim), where `num_queries_total` is the sum of
              `num_denoising_queries` and `num_matching_queries` when
              `self.training` is `True`, else `num_matching_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). The `init_reference` has shape (bs,
              num_queries_total, 4) and each `inter_reference` has shape
              (bs, num_queries, 4) with the last dimension arranged as
              (cx, cy, w, h).
          enc_outputs_class (Tensor): The score of each point on encode
              feature map, has shape (bs, num_feat_points, cls_out_channels).
          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).
          batch_data_samples (list[:obj:`DetDataSample`]): The Data
              Samples. It usually includes information such as
              `gt_instance`, `gt_panoptic_seg` and `gt_sem_seg`.
          dn_meta (Dict[str, int]): The dictionary saves information about
            group collation, including 'num_denoising_queries' and
            'num_denoising_groups'. It will be used for split outputs of
            denoising and matching parts and loss calculation.
  
      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,
          dn_meta,
      )
      losses = self.loss_by_feat(*loss_inputs)
      return losses
  
imports: from typing import Dict, List, Tuple
  import torch
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox_cxcywh_to_xyxy, bbox_overlaps, bbox_xyxy_to_cxcywh
  from mmdet.utils import InstanceList, OptInstanceList, reduce_mean
  from ..losses import QualityFocalLoss
  from ..utils import multi_apply
  from .deformable_detr_head import DeformableDETRHead
label_desc: Use image node_id 1 for calling the DINOHead obj's underlying member method code with example usage: obj.loss(hidden_states, references, enc_outputs_class, enc_outputs_coord, batch_data_samples, dn_meta) and returns: losses