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: Split outputs of the denoising part and the matching part.
  
  For the total outputs of `num_queries_total` length, the former
  `num_denoising_queries` outputs are from denoising queries, and
  the rest `num_matching_queries` ones are from matching queries,
  where `num_queries_total` is the sum of `num_denoising_queries` and
  `num_matching_queries`.
  
  Args:
      all_layers_cls_scores (Tensor): Classification scores of all
          decoder layers, has shape (num_decoder_layers, bs,
          num_queries_total, cls_out_channels).
      all_layers_bbox_preds (Tensor): Regression outputs of all decoder
          layers. Each is a 4D-tensor with normalized coordinate format
          (cx, cy, w, h) and has shape (num_decoder_layers, bs,
          num_queries_total, 4).
      dn_meta (Dict[str, int]): The dictionary saves information about
        group collation, including 'num_denoising_queries' and
        'num_denoising_groups'.
  
  Returns:
      Tuple[Tensor]: a tuple containing the following outputs.
  
      - all_layers_matching_cls_scores (Tensor): Classification scores
        of all decoder layers in matching part, has shape
        (num_decoder_layers, bs, num_matching_queries, cls_out_channels).
      - all_layers_matching_bbox_preds (Tensor): Regression outputs of
        all decoder layers in matching part. Each is a 4D-tensor with
        normalized coordinate format (cx, cy, w, h) and has shape
        (num_decoder_layers, bs, num_matching_queries, 4).
      - 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).
docstr_tok: ["Split","outputs","of","the","denoising","part","and","the","matching","part",".","For","the","total","outputs","of","`","num_queries_total","`","length",",","the","former","`","num_denoising_queries","`","outputs","are","from","denoising","queries",",","and","the","rest","`","num_matching_queries","`","ones","are","from","matching","queries",",","where","`","num_queries_total","`","is","the","sum","of","`","num_denoising_queries","`","and","`","num_matching_queries","`",".","Args",":","all_layers_cls_scores","(","Tensor",")",":","Classification","scores","of","all","decoder","layers",",","has","shape","(","num_decoder_layers",",","bs",",","num_queries_total",",","cls_out_channels",")",".","all_layers_bbox_preds","(","Tensor",")",":","Regression","outputs","of","all","decoder","layers",".","Each","is","a","4D-tensor","with","normalized","coordinate","format","(","cx",",","cy",",","w",",","h",")","and","has","shape","(","num_decoder_layers",",","bs",",","num_queries_total",",","4",")",".","dn_meta","(","Dict","[","str",",","int","]",")",":","The","dictionary","saves","information","about","group","collation",",","including","'num_denoising_queries","'","and","'num_denoising_groups","'",".","Returns",":","Tuple","[","Tensor","]",":","a","tuple","containing","the","following","outputs",".","-","all_layers_matching_cls_scores","(","Tensor",")",":","Classification","scores","of","all","decoder","layers","in","matching","part",",","has","shape","(","num_decoder_layers",",","bs",",","num_matching_queries",",","cls_out_channels",")",".","-","all_layers_matching_bbox_preds","(","Tensor",")",":","Regression","outputs","of","all","decoder","layers","in","matching","part",".","Each","is","a","4D-tensor","with","normalized","coordinate","format","(","cx",",","cy",",","w",",","h",")","and","has","shape","(","num_decoder_layers",",","bs",",","num_matching_queries",",","4",")",".","-","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",")","."]
code: def split_outputs(
      all_layers_cls_scores: Tensor,
      all_layers_bbox_preds: Tensor,
      dn_meta: Dict[str, int],
  ) -> Tuple[Tensor]:
      """Split outputs of the denoising part and the matching part.
  
      For the total outputs of `num_queries_total` length, the former
      `num_denoising_queries` outputs are from denoising queries, and
      the rest `num_matching_queries` ones are from matching queries,
      where `num_queries_total` is the sum of `num_denoising_queries` and
      `num_matching_queries`.
  
      Args:
          all_layers_cls_scores (Tensor): Classification scores of all
              decoder layers, has shape (num_decoder_layers, bs,
              num_queries_total, cls_out_channels).
          all_layers_bbox_preds (Tensor): Regression outputs of all decoder
              layers. Each is a 4D-tensor with normalized coordinate format
              (cx, cy, w, h) and has shape (num_decoder_layers, bs,
              num_queries_total, 4).
          dn_meta (Dict[str, int]): The dictionary saves information about
            group collation, including 'num_denoising_queries' and
            'num_denoising_groups'.
  
      Returns:
          Tuple[Tensor]: a tuple containing the following outputs.
  
          - all_layers_matching_cls_scores (Tensor): Classification scores
            of all decoder layers in matching part, has shape
            (num_decoder_layers, bs, num_matching_queries, cls_out_channels).
          - all_layers_matching_bbox_preds (Tensor): Regression outputs of
            all decoder layers in matching part. Each is a 4D-tensor with
            normalized coordinate format (cx, cy, w, h) and has shape
            (num_decoder_layers, bs, num_matching_queries, 4).
          - 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).
      """
      num_denoising_queries = dn_meta["num_denoising_queries"]
      if dn_meta is not None:
          all_layers_denoising_cls_scores = all_layers_cls_scores[
              :, :, :num_denoising_queries, :
          ]
          all_layers_denoising_bbox_preds = all_layers_bbox_preds[
              :, :, :num_denoising_queries, :
          ]
          all_layers_matching_cls_scores = all_layers_cls_scores[
              :, :, num_denoising_queries:, :
          ]
          all_layers_matching_bbox_preds = all_layers_bbox_preds[
              :, :, num_denoising_queries:, :
          ]
      else:
          all_layers_denoising_cls_scores = None
          all_layers_denoising_bbox_preds = None
          all_layers_matching_cls_scores = all_layers_cls_scores
          all_layers_matching_bbox_preds = all_layers_bbox_preds
      return (
          all_layers_matching_cls_scores,
          all_layers_matching_bbox_preds,
          all_layers_denoising_cls_scores,
          all_layers_denoising_bbox_preds,
      )
  
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 7 for calling the DINOHead obj's underlying member method code with example usage: obj.split_outputs(all_layers_cls_scores, all_layers_bbox_preds, dn_meta) and returns: all_layers_matching_cls_scores,  all_layers_matching_bbox_preds,  all_layers_denoising_cls_scores,  all_layers_denoising_bbox_preds