class_docstr: Head of DETR. DETR:End-to-End Object Detection with Transformers.
  
  More details can be found in the `paper
  <https://arxiv.org/pdf/2005.12872>`_ .
  
  Args:
      num_classes (int): Number of categories excluding the background.
      embed_dims (int): The dims of Transformer embedding.
      num_reg_fcs (int): Number of fully-connected layers used in `FFN`,
          which is then used for the regression head. Defaults to 2.
      sync_cls_avg_factor (bool): Whether to sync the `avg_factor` of
          all ranks. Default to `False`.
      loss_cls (:obj:`ConfigDict` or dict): Config of the classification
          loss. Defaults to `CrossEntropyLoss`.
      loss_bbox (:obj:`ConfigDict` or dict): Config of the regression bbox
          loss. Defaults to `L1Loss`.
      loss_iou (:obj:`ConfigDict` or dict): Config of the regression iou
          loss. Defaults to `GIoULoss`.
      train_cfg (:obj:`ConfigDict` or dict): Training config of transformer
          head.
      test_cfg (:obj:`ConfigDict` or dict): Testing config of transformer
          head.
      init_cfg (:obj:`ConfigDict` or dict, optional): the config to control
          the initialization. Defaults to None.
docstr: Compute regression and classification targets for one image.
  
  Outputs from a single decoder layer of a single feature level are used.
  
  Args:
      cls_score (Tensor): Box score logits from a single decoder layer
          for one image. Shape [num_queries, cls_out_channels].
      bbox_pred (Tensor): Sigmoid outputs from a single decoder layer
          for one image, with normalized coordinate (cx, cy, w, h) and
          shape [num_queries, 4].
      gt_instances (:obj:`InstanceData`): Ground truth of instance
          annotations. It should includes ``bboxes`` and ``labels``
          attributes.
      img_meta (dict): Meta information for one image.
  
  Returns:
      tuple[Tensor]: a tuple containing the following for one image.
  
      - labels (Tensor): Labels of each image.
      - label_weights (Tensor]): Label weights of each image.
      - bbox_targets (Tensor): BBox targets of each image.
      - bbox_weights (Tensor): BBox weights of each image.
      - pos_inds (Tensor): Sampled positive indices for each image.
      - neg_inds (Tensor): Sampled negative indices for each image.
docstr_tok: ["Compute","regression","and","classification","targets","for","one","image",".","Outputs","from","a","single","decoder","layer","of","a","single","feature","level","are","used",".","Args",":","cls_score","(","Tensor",")",":","Box","score","logits","from","a","single","decoder","layer","for","one","image",".","Shape","[","num_queries",",","cls_out_channels","]",".","bbox_pred","(","Tensor",")",":","Sigmoid","outputs","from","a","single","decoder","layer","for","one","image",",","with","normalized","coordinate","(","cx",",","cy",",","w",",","h",")","and","shape","[","num_queries",",","4","]",".","gt_instances","(",":","obj",":","`","InstanceData","`",")",":","Ground","truth","of","instance","annotations",".","It","should","includes","``","bboxes","``","and","``","labels","``","attributes",".","img_meta","(","dict",")",":","Meta","information","for","one","image",".","Returns",":","tuple","[","Tensor","]",":","a","tuple","containing","the","following","for","one","image",".","-","labels","(","Tensor",")",":","Labels","of","each","image",".","-","label_weights","(","Tensor","]",")",":","Label","weights","of","each","image",".","-","bbox_targets","(","Tensor",")",":","BBox","targets","of","each","image",".","-","bbox_weights","(","Tensor",")",":","BBox","weights","of","each","image",".","-","pos_inds","(","Tensor",")",":","Sampled","positive","indices","for","each","image",".","-","neg_inds","(","Tensor",")",":","Sampled","negative","indices","for","each","image","."]
code: def _get_targets_single(
      self,
      cls_score: Tensor,
      bbox_pred: Tensor,
      gt_instances: InstanceData,
      img_meta: dict,
  ) -> tuple:
      """Compute regression and classification targets for one image.
  
      Outputs from a single decoder layer of a single feature level are used.
  
      Args:
          cls_score (Tensor): Box score logits from a single decoder layer
              for one image. Shape [num_queries, cls_out_channels].
          bbox_pred (Tensor): Sigmoid outputs from a single decoder layer
              for one image, with normalized coordinate (cx, cy, w, h) and
              shape [num_queries, 4].
          gt_instances (:obj:`InstanceData`): Ground truth of instance
              annotations. It should includes ``bboxes`` and ``labels``
              attributes.
          img_meta (dict): Meta information for one image.
  
      Returns:
          tuple[Tensor]: a tuple containing the following for one image.
  
          - labels (Tensor): Labels of each image.
          - label_weights (Tensor]): Label weights of each image.
          - bbox_targets (Tensor): BBox targets of each image.
          - bbox_weights (Tensor): BBox weights of each image.
          - pos_inds (Tensor): Sampled positive indices for each image.
          - neg_inds (Tensor): Sampled negative indices for each image.
      """
      img_h, img_w = img_meta["img_shape"]
      factor = bbox_pred.new_tensor(
          [img_w, img_h, img_w, img_h]
      ).unsqueeze(0)
      num_bboxes = bbox_pred.size(0)
      # convert bbox_pred from xywh, normalized to xyxy, unnormalized
      bbox_pred = bbox_cxcywh_to_xyxy(bbox_pred)
      bbox_pred = bbox_pred * factor
  
      pred_instances = InstanceData(scores=cls_score, bboxes=bbox_pred)
      # assigner and sampler
      assign_result = self.assigner.assign(
          pred_instances=pred_instances,
          gt_instances=gt_instances,
          img_meta=img_meta,
      )
  
      gt_bboxes = gt_instances.bboxes
      gt_labels = gt_instances.labels
      pos_inds = (
          torch.nonzero(assign_result.gt_inds > 0, as_tuple=False)
          .squeeze(-1)
          .unique()
      )
      neg_inds = (
          torch.nonzero(assign_result.gt_inds == 0, as_tuple=False)
          .squeeze(-1)
          .unique()
      )
      pos_assigned_gt_inds = assign_result.gt_inds[pos_inds] - 1
      pos_gt_bboxes = gt_bboxes[pos_assigned_gt_inds.long(), :]
  
      # label targets
      labels = gt_bboxes.new_full(
          (num_bboxes,), self.num_classes, dtype=torch.long
      )
      labels[pos_inds] = gt_labels[pos_assigned_gt_inds]
      label_weights = gt_bboxes.new_ones(num_bboxes)
  
      # bbox targets
      bbox_targets = torch.zeros_like(bbox_pred, dtype=gt_bboxes.dtype)
      bbox_weights = torch.zeros_like(bbox_pred, dtype=gt_bboxes.dtype)
      bbox_weights[pos_inds] = 1.0
  
      # DETR regress the relative position of boxes (cxcywh) in the image.
      # Thus the learning target should be normalized by the image size, also
      # the box format should be converted from defaultly x1y1x2y2 to cxcywh.
      pos_gt_bboxes_normalized = pos_gt_bboxes / factor
      pos_gt_bboxes_targets = bbox_xyxy_to_cxcywh(
          pos_gt_bboxes_normalized
      )
      bbox_targets[pos_inds] = pos_gt_bboxes_targets
      return (
          labels,
          label_weights,
          bbox_targets,
          bbox_weights,
          pos_inds,
          neg_inds,
      )
  
imports: from typing import Dict, List, Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import Linear
  from mmcv.cnn.bricks.transformer import FFN
  from mmengine.model import BaseModule
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS, TASK_UTILS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox_cxcywh_to_xyxy, bbox_overlaps, bbox_xyxy_to_cxcywh
  from mmdet.utils import ConfigType, InstanceList, OptInstanceList, OptMultiConfig, reduce_mean
  from ..losses import QualityFocalLoss
  from ..utils import multi_apply
label_desc: Use image node_id 8 for calling the DETRHead obj's underlying member method code with example usage: obj._get_targets_single(cls_score, bbox_pred, gt_instances, img_meta) and returns: labels,  label_weights,  bbox_targets,  bbox_weights,  pos_inds,  neg_inds