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: Forward function for training mode.
  
  Args:
      x (list[Tensor]): Features from backbone.
      img_metas (list[dict]): Meta information of each image, e.g.,
          image size, scaling factor, etc.
      gt_bboxes (Tensor): Ground truth bboxes of the image,
          shape (num_gts, 4).
      gt_labels (Tensor): Ground truth labels of each box,
          shape (num_gts,).
      gt_bboxes_ignore (Tensor): Ground truth bboxes to be
          ignored, shape (num_ignored_gts, 4).
      proposal_cfg (mmcv.Config): Test / postprocessing configuration,
          if None, test_cfg would be used.
  
  Returns:
      dict[str, Tensor]: A dictionary of loss components.
docstr_tok: ["Forward","function","for","training","mode",".","Args",":","x","(","list","[","Tensor","]",")",":","Features","from","backbone",".","img_metas","(","list","[","dict","]",")",":","Meta","information","of","each","image",",","e.g.",",","image","size",",","scaling","factor",",","etc",".","gt_bboxes","(","Tensor",")",":","Ground","truth","bboxes","of","the","image",",","shape","(","num_gts",",","4",")",".","gt_labels","(","Tensor",")",":","Ground","truth","labels","of","each","box",",","shape","(","num_gts",",",")",".","gt_bboxes_ignore","(","Tensor",")",":","Ground","truth","bboxes","to","be","ignored",",","shape","(","num_ignored_gts",",","4",")",".","proposal_cfg","(","mmcv.Config",")",":","Test","\/","postprocessing","configuration",",","if","None",",","test_cfg","would","be","used",".","Returns",":","dict","[","str",",","Tensor","]",":","A","dictionary","of","loss","components","."]
code: def forward_train(
      self,
      x,
      img_metas,
      gt_bboxes,
      gt_labels=None,
      gt_bboxes_ignore=None,
      proposal_cfg=None,
      **kwargs,
  ):
      """Forward function for training mode.
  
      Args:
          x (list[Tensor]): Features from backbone.
          img_metas (list[dict]): Meta information of each image, e.g.,
              image size, scaling factor, etc.
          gt_bboxes (Tensor): Ground truth bboxes of the image,
              shape (num_gts, 4).
          gt_labels (Tensor): Ground truth labels of each box,
              shape (num_gts,).
          gt_bboxes_ignore (Tensor): Ground truth bboxes to be
              ignored, shape (num_ignored_gts, 4).
          proposal_cfg (mmcv.Config): Test / postprocessing configuration,
              if None, test_cfg would be used.
  
      Returns:
          dict[str, Tensor]: A dictionary of loss components.
      """
      assert proposal_cfg is None, '"proposal_cfg" must be None'
      outs = self(x, img_metas)
      if gt_labels is None:
          loss_inputs = outs + (gt_bboxes, img_metas)
      else:
          loss_inputs = outs + (gt_bboxes, gt_labels, img_metas)
      losses = self.loss(
          *loss_inputs, gt_bboxes_ignore=gt_bboxes_ignore
      )
      return losses
  
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 11 for calling the TransformerHead obj's underlying member method code with example usage: obj.forward_train(x, img_metas, gt_bboxes, gt_labels, gt_bboxes_ignore, proposal_cfg) and returns: losses