class_docstr: Implements the DETR transformer head.
  
  See `paper: End-to-End Object Detection with Transformers
  <https://arxiv.org/pdf/2005.12872>`_ for details.
  
  Args:
      num_classes (int): Number of categories excluding the background.
      in_channels (int): Number of channels in the input feature map.
      num_fcs (int, optional): Number of fully-connected layers used in
          `FFN`, which is then used for the regression head. Default 2.
      transformer (dict, optional): Config for transformer.
      positional_encoding (dict, optional): Config for position encoding.
      loss_cls (dict, optional): Config of the classification loss.
          Default `CrossEntropyLoss`.
      loss_bbox (dict, optional): Config of the regression loss.
          Default `L1Loss`.
      loss_iou (dict, optional): Config of the regression iou loss.
          Default `GIoULoss`.
      tran_cfg (dict, optional): Training config of transformer head.
      test_cfg (dict, optional): Testing config of transformer head.
  
  Example:
      >>> import torch
      >>> self = TransformerHead(80, 2048)
      >>> x = torch.rand(1, 2048, 32, 32)
      >>> mask = torch.ones(1, 32, 32).to(x.dtype)
      >>> mask[:, :16, :15] = 0
      >>> all_cls_scores, all_bbox_preds = self(x, mask)
docstr: "Compute regression and classification targets for a batch image.
  
  Outputs from a single decoder layer of a single feature level are used.
  
  Args:
      cls_scores_list (list[Tensor]): Box score logits from a single
          decoder layer for each image with shape [num_query,
          cls_out_channels].
      bbox_preds_list (list[Tensor]): Sigmoid outputs from a single
          decoder layer for each image, with normalized coordinate
          (cx, cy, w, h) and shape [num_query, 4].
      gt_bboxes_list (list[Tensor]): Ground truth bboxes for each image
          with shape (num_gts, 4) in [tl_x, tl_y, br_x, br_y] format.
      gt_labels_list (list[Tensor]): Ground truth class indices for each
          image with shape (num_gts, ).
      img_metas (list[dict]): List of image meta information.
      gt_bboxes_ignore_list (list[Tensor], optional): Bounding
          boxes which can be ignored for each image. Default None.
  
  Returns:
      tuple: a tuple containing the following targets.
  
          - labels_list (list[Tensor]): Labels for all images.
          - label_weights_list (list[Tensor]): Label weights for all                     images.
          - bbox_targets_list (list[Tensor]): BBox targets for all                     images.
          - bbox_weights_list (list[Tensor]): BBox weights for all                     images.
          - num_total_pos (int): Number of positive samples in all                     images.
          - num_total_neg (int): Number of negative samples in all                     images.
docstr_tok: ["``","Compute","regression","and","classification","targets","for","a","batch","image",".","Outputs","from","a","single","decoder","layer","of","a","single","feature","level","are","used",".","Args",":","cls_scores_list","(","list","[","Tensor","]",")",":","Box","score","logits","from","a","single","decoder","layer","for","each","image","with","shape","[","num_query",",","cls_out_channels","]",".","bbox_preds_list","(","list","[","Tensor","]",")",":","Sigmoid","outputs","from","a","single","decoder","layer","for","each","image",",","with","normalized","coordinate","(","cx",",","cy",",","w",",","h",")","and","shape","[","num_query",",","4","]",".","gt_bboxes_list","(","list","[","Tensor","]",")",":","Ground","truth","bboxes","for","each","image","with","shape","(","num_gts",",","4",")","in","[","tl_x",",","tl_y",",","br_x",",","br_y","]","format",".","gt_labels_list","(","list","[","Tensor","]",")",":","Ground","truth","class","indices","for","each","image","with","shape","(","num_gts",",",")",".","img_metas","(","list","[","dict","]",")",":","List","of","image","meta","information",".","gt_bboxes_ignore_list","(","list","[","Tensor","]",",","optional",")",":","Bounding","boxes","which","can","be","ignored","for","each","image",".","Default","None",".","Returns",":","tuple",":","a","tuple","containing","the","following","targets",".","-","labels_list","(","list","[","Tensor","]",")",":","Labels","for","all","images",".","-","label_weights_list","(","list","[","Tensor","]",")",":","Label","weights","for","all","images",".","-","bbox_targets_list","(","list","[","Tensor","]",")",":","BBox","targets","for","all","images",".","-","bbox_weights_list","(","list","[","Tensor","]",")",":","BBox","weights","for","all","images",".","-","num_total_pos","(","int",")",":","Number","of","positive","samples","in","all","images",".","-","num_total_neg","(","int",")",":","Number","of","negative","samples","in","all","images","."]
code: def get_targets(
      self,
      cls_scores_list,
      bbox_preds_list,
      gt_bboxes_list,
      gt_labels_list,
      img_metas,
      gt_bboxes_ignore_list=None,
  ):
      """"Compute regression and classification targets for a batch image.
  
          Outputs from a single decoder layer of a single feature level are used.
  
          Args:
              cls_scores_list (list[Tensor]): Box score logits from a single
                  decoder layer for each image with shape [num_query,
                  cls_out_channels].
              bbox_preds_list (list[Tensor]): Sigmoid outputs from a single
                  decoder layer for each image, with normalized coordinate
                  (cx, cy, w, h) and shape [num_query, 4].
              gt_bboxes_list (list[Tensor]): Ground truth bboxes for each image
                  with shape (num_gts, 4) in [tl_x, tl_y, br_x, br_y] format.
              gt_labels_list (list[Tensor]): Ground truth class indices for each
                  image with shape (num_gts, ).
              img_metas (list[dict]): List of image meta information.
              gt_bboxes_ignore_list (list[Tensor], optional): Bounding
                  boxes which can be ignored for each image. Default None.
  
          Returns:
              tuple: a tuple containing the following targets.
  
                  - labels_list (list[Tensor]): Labels for all images.
                  - label_weights_list (list[Tensor]): Label weights for all \
                      images.
                  - bbox_targets_list (list[Tensor]): BBox targets for all \
                      images.
                  - bbox_weights_list (list[Tensor]): BBox weights for all \
                      images.
                  - num_total_pos (int): Number of positive samples in all \
                      images.
                  - num_total_neg (int): Number of negative samples in all \
                      images.
          """
      assert (
          gt_bboxes_ignore_list is None
      ), "Only supports for gt_bboxes_ignore setting to None."
      num_imgs = len(cls_scores_list)
      gt_bboxes_ignore_list = [
          gt_bboxes_ignore_list for _ in range(num_imgs)
      ]
  
      (
          labels_list,
          label_weights_list,
          bbox_targets_list,
          bbox_weights_list,
          pos_inds_list,
          neg_inds_list,
      ) = multi_apply(
          self._get_target_single,
          cls_scores_list,
          bbox_preds_list,
          gt_bboxes_list,
          gt_labels_list,
          img_metas,
          gt_bboxes_ignore_list,
      )
      num_total_pos = sum((inds.numel() for inds in pos_inds_list))
      num_total_neg = sum((inds.numel() for inds in neg_inds_list))
      return (
          labels_list,
          label_weights_list,
          bbox_targets_list,
          bbox_weights_list,
          num_total_pos,
          num_total_neg,
      )
  
imports: import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import Conv2d, Linear, build_activation_layer
  from mmcv.runner import force_fp32
  from mmdet.core import bbox_cxcywh_to_xyxy, bbox_xyxy_to_cxcywh, build_assigner, build_sampler, multi_apply, reduce_mean
  from mmdet.models.utils import FFN, build_positional_encoding, build_transformer
  from ..builder import HEADS, build_loss
  from .anchor_free_head import AnchorFreeHead
label_desc: Use image node_id 9 for calling the TransformerHead obj's underlying member method code with example usage: obj.get_targets(cls_scores_list, bbox_preds_list, gt_bboxes_list, gt_labels_list, img_metas, gt_bboxes_ignore_list) and returns: labels_list,  label_weights_list,  bbox_targets_list,  bbox_weights_list,  num_total_pos,  num_total_neg