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.
code: def __init__(
      self,
      num_classes: int,
      embed_dims: int = 256,
      num_reg_fcs: int = 2,
      sync_cls_avg_factor: bool = False,
      loss_cls: ConfigType = dict(
          type="CrossEntropyLoss",
          bg_cls_weight=0.1,
          use_sigmoid=False,
          loss_weight=1.0,
          class_weight=1.0,
      ),
      loss_bbox: ConfigType = dict(type="L1Loss", loss_weight=5.0),
      loss_iou: ConfigType = dict(type="GIoULoss", loss_weight=2.0),
      train_cfg: ConfigType = dict(
          assigner=dict(
              type="HungarianAssigner",
              match_costs=[
                  dict(type="ClassificationCost", weight=1.0),
                  dict(
                      type="BBoxL1Cost", weight=5.0, box_format="xywh"
                  ),
                  dict(type="IoUCost", iou_mode="giou", weight=2.0),
              ],
          )
      ),
      test_cfg: ConfigType = dict(max_per_img=100),
      init_cfg: OptMultiConfig = None,
  ) -> None:
      super().__init__(init_cfg=init_cfg)
      self.bg_cls_weight = 0
      self.sync_cls_avg_factor = sync_cls_avg_factor
      class_weight = loss_cls.get("class_weight", None)
      if class_weight is not None and (self.__class__ is DETRHead):
          assert isinstance(class_weight, float), (
              "Expected "
              "class_weight to have type float. Found "
              f"{type(class_weight)}."
          )
          # NOTE following the official DETR repo, bg_cls_weight means
          # relative classification weight of the no-object class.
          bg_cls_weight = loss_cls.get("bg_cls_weight", class_weight)
          assert isinstance(bg_cls_weight, float), (
              "Expected "
              "bg_cls_weight to have type float. Found "
              f"{type(bg_cls_weight)}."
          )
          class_weight = torch.ones(num_classes + 1) * class_weight
          # set background class as the last indice
          class_weight[num_classes] = bg_cls_weight
          loss_cls.update({"class_weight": class_weight})
          if "bg_cls_weight" in loss_cls:
              loss_cls.pop("bg_cls_weight")
          self.bg_cls_weight = bg_cls_weight
  
      if train_cfg:
          assert "assigner" in train_cfg, (
              "assigner should be provided " "when train_cfg is set."
          )
          assigner = train_cfg["assigner"]
          self.assigner = TASK_UTILS.build(assigner)
          if train_cfg.get("sampler", None) is not None:
              raise RuntimeError("DETR do not build sampler.")
      self.num_classes = num_classes
      self.embed_dims = embed_dims
      self.num_reg_fcs = num_reg_fcs
      self.train_cfg = train_cfg
      self.test_cfg = test_cfg
      self.loss_cls = MODELS.build(loss_cls)
      self.loss_bbox = MODELS.build(loss_bbox)
      self.loss_iou = MODELS.build(loss_iou)
  
      if self.loss_cls.use_sigmoid:
          self.cls_out_channels = num_classes
      else:
          self.cls_out_channels = num_classes + 1
  
      self._init_layers()
  
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 1 to create a new DETRHead object from inherited base classes: BaseModule with example: obj = DETRHead(num_classes, embed_dims, num_reg_fcs, sync_cls_avg_factor, loss_cls, loss_bbox, loss_iou, train_cfg, test_cfg, init_cfg)