code: def prepare_diffusion(self, gt_boxes, image_size):
      device = gt_boxes.device
      time = torch.randint(
          0, self.timesteps, (1,), dtype=torch.long, device=device
      )
      noise = torch.randn(self.num_proposals, 4, device=device)
  
      num_gt = gt_boxes.shape[0]
      if num_gt < self.num_proposals:
          # 3 * sigma = 1/2 --> sigma: 1/6
          box_placeholder = (
              torch.randn(self.num_proposals - num_gt, 4, device=device)
              / 6.0
              + 0.5
          )
          box_placeholder[:, 2:] = torch.clip(
              box_placeholder[:, 2:], min=1e-4
          )
          x_start = torch.cat((gt_boxes, box_placeholder), dim=0)
      else:
          select_mask = [True] * self.num_proposals + [False] * (
              num_gt - self.num_proposals
          )
          random.shuffle(select_mask)
          x_start = gt_boxes[select_mask]
  
      x_start = (x_start * 2.0 - 1.0) * self.snr_scale
  
      # noise sample
      x = self.q_sample(x_start=x_start, time=time, noise=noise)
  
      x = torch.clamp(x, min=-1 * self.snr_scale, max=self.snr_scale)
      x = ((x / self.snr_scale) + 1) / 2.0
  
      diff_bboxes = bbox_cxcywh_to_xyxy(x)
      # convert to abs bboxes
      diff_bboxes_abs = diff_bboxes * image_size
  
      metainfo = dict(time=time.squeeze(-1))
      pred_instances = InstanceData(metainfo=metainfo)
      pred_instances.diff_bboxes = diff_bboxes
      pred_instances.diff_bboxes_abs = diff_bboxes_abs
      pred_instances.noise = noise
      return pred_instances
  
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 7 for calling the DynamicDiffusionDetHead obj's underlying member method code with example usage: obj.prepare_diffusion(gt_boxes, image_size) and returns: pred_instances