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: Calculate denoising loss.
  
  Args:
      all_layers_denoising_cls_scores (Tensor): Classification scores of
          all decoder layers in denoising part, has shape (
          num_decoder_layers, bs, num_denoising_queries,
          cls_out_channels).
      all_layers_denoising_bbox_preds (Tensor): Regression outputs of all
          decoder layers in denoising part. Each is a 4D-tensor with
          normalized coordinate format (cx, cy, w, h) and has shape
          (num_decoder_layers, bs, num_denoising_queries, 4).
      batch_gt_instances (list[:obj:`InstanceData`]): Batch of
          gt_instance. It usually includes ``bboxes`` and ``labels``
          attributes.
      batch_img_metas (list[dict]): Meta information of each image, e.g.,
          image size, scaling factor, etc.
      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:
      Tuple[List[Tensor]]: The loss_dn_cls, loss_dn_bbox, and loss_dn_iou
      of each decoder layers.
docstr_tok: ["Calculate","denoising","loss",".","Args",":","all_layers_denoising_cls_scores","(","Tensor",")",":","Classification","scores","of","all","decoder","layers","in","denoising","part",",","has","shape","(","num_decoder_layers",",","bs",",","num_denoising_queries",",","cls_out_channels",")",".","all_layers_denoising_bbox_preds","(","Tensor",")",":","Regression","outputs","of","all","decoder","layers","in","denoising","part",".","Each","is","a","4D-tensor","with","normalized","coordinate","format","(","cx",",","cy",",","w",",","h",")","and","has","shape","(","num_decoder_layers",",","bs",",","num_denoising_queries",",","4",")",".","batch_gt_instances","(","list","[",":","obj",":","`","InstanceData","`","]",")",":","Batch","of","gt_instance",".","It","usually","includes","``","bboxes","``","and","``","labels","``","attributes",".","batch_img_metas","(","list","[","dict","]",")",":","Meta","information","of","each","image",",","e.g.",",","image","size",",","scaling","factor",",","etc",".","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",":","Tuple","[","List","[","Tensor","]","]",":","The","loss_dn_cls",",","loss_dn_bbox",",","and","loss_dn_iou","of","each","decoder","layers","."]
code: def loss_dn(
      self,
      all_layers_denoising_cls_scores: Tensor,
      all_layers_denoising_bbox_preds: Tensor,
      batch_gt_instances: InstanceList,
      batch_img_metas: List[dict],
      dn_meta: Dict[str, int],
  ) -> Tuple[List[Tensor]]:
      """Calculate denoising loss.
  
      Args:
          all_layers_denoising_cls_scores (Tensor): Classification scores of
              all decoder layers in denoising part, has shape (
              num_decoder_layers, bs, num_denoising_queries,
              cls_out_channels).
          all_layers_denoising_bbox_preds (Tensor): Regression outputs of all
              decoder layers in denoising part. Each is a 4D-tensor with
              normalized coordinate format (cx, cy, w, h) and has shape
              (num_decoder_layers, bs, num_denoising_queries, 4).
          batch_gt_instances (list[:obj:`InstanceData`]): Batch of
              gt_instance. It usually includes ``bboxes`` and ``labels``
              attributes.
          batch_img_metas (list[dict]): Meta information of each image, e.g.,
              image size, scaling factor, etc.
          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:
          Tuple[List[Tensor]]: The loss_dn_cls, loss_dn_bbox, and loss_dn_iou
          of each decoder layers.
      """
      return multi_apply(
          self._loss_dn_single,
          all_layers_denoising_cls_scores,
          all_layers_denoising_bbox_preds,
          batch_gt_instances=batch_gt_instances,
          batch_img_metas=batch_img_metas,
          dn_meta=dn_meta,
      )
  
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 3 for calling the DINOHead obj's underlying member method code with example usage: obj.loss_dn(all_layers_denoising_cls_scores, all_layers_denoising_bbox_preds, batch_gt_instances, batch_img_metas, dn_meta) and returns: multi_apply