code: def __init__(
      self,
      num_classes=80,
      feat_channels=256,
      num_proposals=500,
      num_heads=6,
      prior_prob=0.01,
      snr_scale=2.0,
      timesteps=1000,
      sampling_timesteps=1,
      self_condition=False,
      box_renewal=True,
      use_ensemble=True,
      deep_supervision=True,
      ddim_sampling_eta=1.0,
      criterion=dict(
          type="DiffusionDetCriterion",
          num_classes=80,
          assigner=dict(
              type="DiffusionDetMatcher",
              match_costs=[
                  dict(
                      type="FocalLossCost",
                      alpha=2.0,
                      gamma=0.25,
                      weight=2.0,
                  ),
                  dict(
                      type="BBoxL1Cost", weight=5.0, box_format="xyxy"
                  ),
                  dict(type="IoUCost", iou_mode="giou", weight=2.0),
              ],
              center_radius=2.5,
              candidate_topk=5,
          ),
      ),
      single_head=dict(
          type="DiffusionDetHead",
          num_cls_convs=1,
          num_reg_convs=3,
          dim_feedforward=2048,
          num_heads=8,
          dropout=0.0,
          act_cfg=dict(type="ReLU"),
          dynamic_conv=dict(dynamic_dim=64, dynamic_num=2),
      ),
      roi_extractor=dict(
          type="SingleRoIExtractor",
          roi_layer=dict(
              type="RoIAlign", output_size=7, sampling_ratio=2
          ),
          out_channels=256,
          featmap_strides=[4, 8, 16, 32],
      ),
      test_cfg=None,
      **kwargs,
  ) -> None:
      super().__init__()
      self.roi_extractor = MODELS.build(roi_extractor)
  
      self.num_classes = num_classes
      self.num_classes = num_classes
      self.feat_channels = feat_channels
      self.num_proposals = num_proposals
      self.num_heads = num_heads
      # Build Diffusion
      assert isinstance(timesteps, int), (
          "The type of `timesteps` should "
          f"be int but got {type(timesteps)}"
      )
      assert sampling_timesteps <= timesteps
      self.timesteps = timesteps
      self.sampling_timesteps = sampling_timesteps
      self.snr_scale = snr_scale
  
      self.ddim_sampling = self.sampling_timesteps < self.timesteps
      self.ddim_sampling_eta = ddim_sampling_eta
      self.self_condition = self_condition
      self.box_renewal = box_renewal
      self.use_ensemble = use_ensemble
  
      self._build_diffusion()
  
      # Build assigner
      assert criterion.get("assigner", None) is not None
      assigner = TASK_UTILS.build(criterion.get("assigner"))
      # Init parameters.
      self.use_focal_loss = assigner.use_focal_loss
      self.use_fed_loss = assigner.use_fed_loss
  
      # build criterion
      criterion.update(deep_supervision=deep_supervision)
      self.criterion = TASK_UTILS.build(criterion)
  
      # Build Dynamic Head.
      single_head_ = single_head.copy()
      single_head_num_classes = single_head_.get("num_classes", None)
      if single_head_num_classes is None:
          single_head_.update(num_classes=num_classes)
      else:
          if single_head_num_classes != num_classes:
              warnings.warn(
                  "The `num_classes` of `DynamicDiffusionDetHead` and "
                  "`SingleDiffusionDetHead` should be same, changing "
                  f"`single_head.num_classes` to {num_classes}"
              )
              single_head_.update(num_classes=num_classes)
  
      single_head_feat_channels = single_head_.get(
          "feat_channels", None
      )
      if single_head_feat_channels is None:
          single_head_.update(feat_channels=feat_channels)
      else:
          if single_head_feat_channels != feat_channels:
              warnings.warn(
                  "The `feat_channels` of `DynamicDiffusionDetHead` and "
                  "`SingleDiffusionDetHead` should be same, changing "
                  f"`single_head.feat_channels` to {feat_channels}"
              )
              single_head_.update(feat_channels=feat_channels)
  
      default_pooler_resolution = roi_extractor["roi_layer"].get(
          "output_size"
      )
      assert default_pooler_resolution is not None
      single_head_pooler_resolution = single_head_.get(
          "pooler_resolution"
      )
      if single_head_pooler_resolution is None:
          single_head_.update(
              pooler_resolution=default_pooler_resolution
          )
      else:
          if single_head_pooler_resolution != default_pooler_resolution:
              warnings.warn(
                  "The `pooler_resolution` of `DynamicDiffusionDetHead` "
                  "and `SingleDiffusionDetHead` should be same, changing "
                  f"`single_head.pooler_resolution` to {num_classes}"
              )
              single_head_.update(
                  pooler_resolution=default_pooler_resolution
              )
  
      single_head_.update(
          use_focal_loss=self.use_focal_loss,
          use_fed_loss=self.use_fed_loss,
      )
      single_head_module = MODELS.build(single_head_)
  
      self.num_heads = num_heads
      self.head_series = nn.ModuleList(
          [copy.deepcopy(single_head_module) for _ in range(num_heads)]
      )
  
      self.deep_supervision = deep_supervision
  
      # Gaussian random feature embedding layer for time
      time_dim = feat_channels * 4
      self.time_mlp = nn.Sequential(
          SinusoidalPositionEmbeddings(feat_channels),
          nn.Linear(feat_channels, time_dim),
          nn.GELU(),
          nn.Linear(time_dim, time_dim),
      )
  
      self.prior_prob = prior_prob
      self.test_cfg = test_cfg
      self.use_nms = self.test_cfg.get("use_nms", True)
      self._init_weights()
  
imports: import copy
  import math
  import random
  import warnings
  from typing import Tuple
  import torch
  import torch.nn
  import torch.nn.functional
  from mmcv.cnn import build_activation_layer
  from mmcv.ops import batched_nms
  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 bbox2roi, bbox_cxcywh_to_xyxy, bbox_xyxy_to_cxcywh, get_box_wh, scale_boxes
  from mmdet.utils import InstanceList
label_desc: Use image node_id 1 to create a new DynamicDiffusionDetHead object from inherited base classes: nn with example: obj = DynamicDiffusionDetHead(num_classes, feat_channels, num_proposals, num_heads, prior_prob, snr_scale, timesteps, sampling_timesteps, _condition, box_renewal, use_ensemble, deep_supervision, ddim_sampling_eta, criterion, single_head, roi_extractor, test_cfg)