class_docstr: Head of DDQDETR: Dense Distinct Query for
      End-to-End Object Detection.
  
  Code is modified from the `official github repo
      <https://github.com/jshilong/DDQ>`_.
  
  More details can be found in the `paper
      <https://arxiv.org/abs/2303.12776>`_ .
  
  Args:
      aux_num_pos (int): Number of positive targets assigned to a
          perdicted object. Defaults to 4.
docstr: Transform a batch of output features extracted from the head into
  bbox results.
  
  Args:
      layer_cls_scores (Tensor): Classification scores of all
          decoder layers, has shape (num_decoder_layers, bs,
          num_queries, cls_out_channels).
      layer_bbox_preds (Tensor): Bbox coordinates of all decoder layers.
          Each has shape (num_decoder_layers, bs, num_queries, 4)
          with normalized coordinate format (cx, cy, w, h).
      batch_img_metas (list[dict]): Meta information of each image.
      rescale (bool, optional): If `True`, return boxes in original
          image space. Default `False`.
  
  Returns:
      list[obj:`InstanceData`]: Detection results of each image
      after the post process.
docstr_tok: ["Transform","a","batch","of","output","features","extracted","from","the","head","into","bbox","results",".","Args",":","layer_cls_scores","(","Tensor",")",":","Classification","scores","of","all","decoder","layers",",","has","shape","(","num_decoder_layers",",","bs",",","num_queries",",","cls_out_channels",")",".","layer_bbox_preds","(","Tensor",")",":","Bbox","coordinates","of","all","decoder","layers",".","Each","has","shape","(","num_decoder_layers",",","bs",",","num_queries",",","4",")","with","normalized","coordinate","format","(","cx",",","cy",",","w",",","h",")",".","batch_img_metas","(","list","[","dict","]",")",":","Meta","information","of","each","image",".","rescale","(","bool",",","optional",")",":","If","`","True","`",",","return","boxes","in","original","image","space",".","Default","`","False","`",".","Returns",":","list","[","obj",":","`","InstanceData","`","]",":","Detection","results","of","each","image","after","the","post","process","."]
code: def predict_by_feat(
      self,
      layer_cls_scores: Tensor,
      layer_bbox_preds: Tensor,
      batch_img_metas: List[dict],
      rescale: bool = True,
  ) -> InstanceList:
      """Transform a batch of output features extracted from the head into
      bbox results.
  
      Args:
          layer_cls_scores (Tensor): Classification scores of all
              decoder layers, has shape (num_decoder_layers, bs,
              num_queries, cls_out_channels).
          layer_bbox_preds (Tensor): Bbox coordinates of all decoder layers.
              Each has shape (num_decoder_layers, bs, num_queries, 4)
              with normalized coordinate format (cx, cy, w, h).
          batch_img_metas (list[dict]): Meta information of each image.
          rescale (bool, optional): If `True`, return boxes in original
              image space. Default `False`.
  
      Returns:
          list[obj:`InstanceData`]: Detection results of each image
          after the post process.
      """
      cls_scores = layer_cls_scores[-1]
      bbox_preds = layer_bbox_preds[-1]
  
      num_imgs = cls_scores.size(0)
      # -1 is last layer input query mask
  
      batch_mask = [
          self.cache_dict["distinct_query_mask"][-1][
              img_id * self.cache_dict["num_heads"]
          ][0]
          for img_id in range(num_imgs)
      ]
  
      result_list = []
      for img_id in range(len(batch_img_metas)):
          cls_score = cls_scores[img_id][batch_mask[img_id]]
          bbox_pred = bbox_preds[img_id][batch_mask[img_id]]
          img_meta = batch_img_metas[img_id]
          results = self._predict_by_feat_single(
              cls_score, bbox_pred, img_meta, rescale
          )
          result_list.append(results)
      return result_list
  
imports: import copy
  from typing import Dict, List, Tuple
  import torch
  from mmengine.model import bias_init_with_prob, constant_init
  from torch import Tensor, nn
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox_cxcywh_to_xyxy
  from mmdet.utils import InstanceList, OptInstanceList, reduce_mean
  from ..layers import inverse_sigmoid
  from ..losses import DDQAuxLoss
  from ..utils import multi_apply
  from .dino_head import DINOHead
label_desc: Use image node_id 9 for calling the DDQDETRHead obj's underlying member method code with example usage: obj.predict_by_feat(layer_cls_scores, layer_bbox_preds, batch_img_metas, rescale) and returns: result_list