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`.
docstr: Calculate denoising query groups number.
  
  Two grouping strategies, 'static dn groups' and 'dynamic dn groups',
  are supported. When `self.dynamic_dn_groups` is `False`, the number
  of denoising query groups will always be `self.num_groups`. When
  `self.dynamic_dn_groups` is `True`, the group number will be dynamic,
  ensuring the denoising queries number will not exceed
  `self.num_dn_queries` to prevent large fluctuations of memory.
  
  NOTE The `num_group` is shared for different samples in a batch. When
  the target numbers in the samples varies, the denoising queries of the
  samples containing fewer targets are padded to the max length.
  
  Args:
      max_num_target (int, optional): The max target number of the batch
          samples. It will only be used when `self.dynamic_dn_groups` is
          `True`. Defaults to `None`.
  
  Returns:
      int: The denoising group number of the current batch.
docstr_tok: ["Calculate","denoising","query","groups","number",".","Two","grouping","strategies",",","'static","dn","groups","'","and","'dynamic","dn","groups","'",",","are","supported",".","When","`","self.dynamic_dn_groups","`","is","`","False","`",",","the","number","of","denoising","query","groups","will","always","be","`","self.num_groups","`",".","When","`","self.dynamic_dn_groups","`","is","`","True","`",",","the","group","number","will","be","dynamic",",","ensuring","the","denoising","queries","number","will","not","exceed","`","self.num_dn_queries","`","to","prevent","large","fluctuations","of","memory",".","NOTE","The","`","num_group","`","is","shared","for","different","samples","in","a","batch",".","When","the","target","numbers","in","the","samples","varies",",","the","denoising","queries","of","the","samples","containing","fewer","targets","are","padded","to","the","max","length",".","Args",":","max_num_target","(","int",",","optional",")",":","The","max","target","number","of","the","batch","samples",".","It","will","only","be","used","when","`","self.dynamic_dn_groups","`","is","`","True","`",".","Defaults","to","`","None","`",".","Returns",":","int",":","The","denoising","group","number","of","the","current","batch","."]
code: def get_num_groups(self, max_num_target: int = None) -> int:
      """Calculate denoising query groups number.
  
      Two grouping strategies, 'static dn groups' and 'dynamic dn groups',
      are supported. When `self.dynamic_dn_groups` is `False`, the number
      of denoising query groups will always be `self.num_groups`. When
      `self.dynamic_dn_groups` is `True`, the group number will be dynamic,
      ensuring the denoising queries number will not exceed
      `self.num_dn_queries` to prevent large fluctuations of memory.
  
      NOTE The `num_group` is shared for different samples in a batch. When
      the target numbers in the samples varies, the denoising queries of the
      samples containing fewer targets are padded to the max length.
  
      Args:
          max_num_target (int, optional): The max target number of the batch
              samples. It will only be used when `self.dynamic_dn_groups` is
              `True`. Defaults to `None`.
  
      Returns:
          int: The denoising group number of the current batch.
      """
      if self.dynamic_dn_groups:
          assert max_num_target is not None, (
              "group_queries should be provided when using "
              "dynamic dn groups"
          )
          if max_num_target == 0:
              num_groups = 1
          else:
              num_groups = self.num_dn_queries // max_num_target
      else:
          num_groups = self.num_groups
      if num_groups < 1:
          num_groups = 1
      return int(num_groups)
  
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 3 for calling the CdnQueryGenerator obj's underlying member method code with example usage: obj.get_num_groups(max_num_target) and returns: int