class_docstr: Implement query generator of the Contrastive denoising (CDN) proposed in
  `DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object
  Detection <https://arxiv.org/abs/2203.03605>`_
  
  Code is modified from the `official github repo
  <https://github.com/IDEA-Research/DINO>`_.
  
  Args:
      num_classes (int): Number of object classes.
      embed_dims (int): The embedding dimensions of the generated queries.
      num_matching_queries (int): The queries number of the matching part.
          Used for generating dn_mask.
      label_noise_scale (float): The scale of label noise, defaults to 0.5.
      box_noise_scale (float): The scale of box noise, defaults to 1.0.
      group_cfg (:obj:`ConfigDict` or dict, optional): The config of the
          denoising queries grouping, includes `dynamic`, `num_dn_queries`,
          and `num_groups`. Two grouping strategies, 'static dn groups' and
          'dynamic dn groups', are supported. When `dynamic` is `False`,
          the `num_groups` should be set, and the number of denoising query
          groups will always be `num_groups`. When `dynamic` is `True`, the
          `num_dn_queries` should be set, and the group number will be
          dynamic to ensure that the denoising queries number will not exceed
          `num_dn_queries` to prevent large fluctuations of memory. Defaults
          to `None`.
code: def __init__(
      self,
      num_classes: int,
      embed_dims: int,
      num_matching_queries: int,
      label_noise_scale: float = 0.5,
      box_noise_scale: float = 1.0,
      group_cfg: OptConfigType = None,
  ) -> None:
      super().__init__()
      self.num_classes = num_classes
      self.embed_dims = embed_dims
      self.num_matching_queries = num_matching_queries
      self.label_noise_scale = label_noise_scale
      self.box_noise_scale = box_noise_scale
  
      # prepare grouping strategy
      group_cfg = {} if group_cfg is None else group_cfg
      self.dynamic_dn_groups = group_cfg.get("dynamic", True)
      if self.dynamic_dn_groups:
          if "num_dn_queries" not in group_cfg:
              warnings.warn(
                  "'num_dn_queries' should be set when using "
                  "dynamic dn groups, use 100 as default."
              )
          self.num_dn_queries = group_cfg.get("num_dn_queries", 100)
          assert isinstance(self.num_dn_queries, int), (
              f"Expected the num_dn_queries to have type int, but got "
              f"{self.num_dn_queries}({type(self.num_dn_queries)}). "
          )
      else:
          assert (
              "num_groups" in group_cfg
          ), "num_groups should be set when using static dn groups"
          self.num_groups = group_cfg["num_groups"]
          assert isinstance(self.num_groups, int), (
              f"Expected the num_groups to have type int, but got "
              f"{self.num_groups}({type(self.num_groups)}). "
          )
  
      # NOTE The original repo of DINO set the num_embeddings 92 for coco,
      # 91 (0~90) of which represents target classes and the 92 (91)
      # indicates `Unknown` class. However, the embedding of `unknown` class
      # is not used in the original DINO.
      # TODO: num_classes + 1 or num_classes ?
      self.label_embedding = nn.Embedding(
          self.num_classes, self.embed_dims
      )
  
imports: import warnings
  from typing import Tuple, Union
  import torch
  from mmengine.model import BaseModule
  from torch import Tensor, nn
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import bbox_xyxy_to_cxcywh
  from mmdet.utils import OptConfigType
  from .deformable_detr_layers import DeformableDetrTransformerDecoder
  from .utils import MLP, coordinate_to_encoding, inverse_sigmoid
label_desc: Use image node_id 1 to create a new CdnQueryGenerator object from inherited base classes: BaseModule with example: obj = CdnQueryGenerator(num_classes, embed_dims, num_matching_queries, label_noise_scale, box_noise_scale, group_cfg)