code: def predict_by_feat(
      self,
      x,
      time_pairs,
      batch_noise_bboxes,
      batch_noise_bboxes_raw,
      batch_image_size,
      device,
      batch_img_metas=None,
      cfg=None,
      rescale=True,
  ):
      batch_size = len(batch_img_metas)
  
      cfg = self.test_cfg if cfg is None else cfg
      cfg = copy.deepcopy(cfg)
  
      ensemble_score, ensemble_label, ensemble_coord = [], [], []
      for time, time_next in time_pairs:
          batch_time = torch.full(
              (batch_size,), time, device=device, dtype=torch.long
          )
          # self_condition = x_start if self.self_condition else None
          pred_logits, pred_bboxes = self(
              x, batch_noise_bboxes, batch_time
          )
  
          x_start = pred_bboxes[-1]
  
          x_start = x_start / batch_image_size[:, None, :]
          x_start = bbox_xyxy_to_cxcywh(x_start)
          x_start = (x_start * 2 - 1.0) * self.snr_scale
          x_start = torch.clamp(
              x_start, min=-1 * self.snr_scale, max=self.snr_scale
          )
          pred_noise = self.predict_noise_from_start(
              batch_noise_bboxes_raw, batch_time, x_start
          )
          pred_noise_list, x_start_list = [], []
          noise_bboxes_list, num_remain_list = [], []
          if self.box_renewal:  # filter
              score_thr = cfg.get("score_thr", 0)
              for img_id in range(batch_size):
                  score_per_image = pred_logits[-1][img_id]
  
                  score_per_image = torch.sigmoid(score_per_image)
                  value, _ = torch.max(
                      score_per_image, -1, keepdim=False
                  )
                  keep_idx = value > score_thr
  
                  num_remain_list.append(torch.sum(keep_idx))
                  pred_noise_list.append(
                      pred_noise[img_id, keep_idx, :]
                  )
                  x_start_list.append(x_start[img_id, keep_idx, :])
                  noise_bboxes_list.append(
                      batch_noise_bboxes[img_id, keep_idx, :]
                  )
          if time_next < 0:
              # Not same as original DiffusionDet
              if self.use_ensemble and self.sampling_timesteps > 1:
                  (
                      box_pred_per_image,
                      scores_per_image,
                      labels_per_image,
                  ) = self.inference(
                      box_cls=pred_logits[-1],
                      box_pred=pred_bboxes[-1],
                      cfg=cfg,
                      device=device,
                  )
                  ensemble_score.append(scores_per_image)
                  ensemble_label.append(labels_per_image)
                  ensemble_coord.append(box_pred_per_image)
              continue
  
          alpha = self.alphas_cumprod[time]
          alpha_next = self.alphas_cumprod[time_next]
  
          sigma = (
              self.ddim_sampling_eta
              * (
                  (1 - alpha / alpha_next)
                  * (1 - alpha_next)
                  / (1 - alpha)
              ).sqrt()
          )
          c = (1 - alpha_next - sigma**2).sqrt()
  
          batch_noise_bboxes_list = []
          batch_noise_bboxes_raw_list = []
          for idx in range(batch_size):
              pred_noise = pred_noise_list[idx]
              x_start = x_start_list[idx]
              noise_bboxes = noise_bboxes_list[idx]
              num_remain = num_remain_list[idx]
              noise = torch.randn_like(noise_bboxes)
  
              noise_bboxes = (
                  x_start * alpha_next.sqrt()
                  + c * pred_noise
                  + sigma * noise
              )
  
              if self.box_renewal:  # filter
                  # replenish with randn boxes
                  if num_remain < self.num_proposals:
                      noise_bboxes = torch.cat(
                          (
                              noise_bboxes,
                              torch.randn(
                                  self.num_proposals - num_remain,
                                  4,
                                  device=device,
                              ),
                          ),
                          dim=0,
                      )
                  else:
                      select_mask = [True] * self.num_proposals + [
                          False
                      ] * (num_remain - self.num_proposals)
                      random.shuffle(select_mask)
                      noise_bboxes = noise_bboxes[select_mask]
  
                  # raw noise boxes
                  batch_noise_bboxes_raw_list.append(noise_bboxes)
                  # resize to xyxy
                  noise_bboxes = torch.clamp(
                      noise_bboxes,
                      min=-1 * self.snr_scale,
                      max=self.snr_scale,
                  )
                  noise_bboxes = (
                      (noise_bboxes / self.snr_scale) + 1
                  ) / 2
                  noise_bboxes = bbox_cxcywh_to_xyxy(noise_bboxes)
                  noise_bboxes = noise_bboxes * batch_image_size[idx]
  
              batch_noise_bboxes_list.append(noise_bboxes)
          batch_noise_bboxes = torch.stack(batch_noise_bboxes_list)
          batch_noise_bboxes_raw = torch.stack(
              batch_noise_bboxes_raw_list
          )
          if self.use_ensemble and self.sampling_timesteps > 1:
              (
                  box_pred_per_image,
                  scores_per_image,
                  labels_per_image,
              ) = self.inference(
                  box_cls=pred_logits[-1],
                  box_pred=pred_bboxes[-1],
                  cfg=cfg,
                  device=device,
              )
              ensemble_score.append(scores_per_image)
              ensemble_label.append(labels_per_image)
              ensemble_coord.append(box_pred_per_image)
      if self.use_ensemble and self.sampling_timesteps > 1:
          steps = len(ensemble_score)
          results_list = []
          for idx in range(batch_size):
              ensemble_score_per_img = [
                  ensemble_score[i][idx] for i in range(steps)
              ]
              ensemble_label_per_img = [
                  ensemble_label[i][idx] for i in range(steps)
              ]
              ensemble_coord_per_img = [
                  ensemble_coord[i][idx] for i in range(steps)
              ]
  
              scores_per_image = torch.cat(
                  ensemble_score_per_img, dim=0
              )
              labels_per_image = torch.cat(
                  ensemble_label_per_img, dim=0
              )
              box_pred_per_image = torch.cat(
                  ensemble_coord_per_img, dim=0
              )
  
              if self.use_nms:
                  det_bboxes, keep_idxs = batched_nms(
                      box_pred_per_image,
                      scores_per_image,
                      labels_per_image,
                      cfg.nms,
                  )
                  box_pred_per_image = box_pred_per_image[keep_idxs]
                  labels_per_image = labels_per_image[keep_idxs]
                  scores_per_image = det_bboxes[:, -1]
              results = InstanceData()
              results.bboxes = box_pred_per_image
              results.scores = scores_per_image
              results.labels = labels_per_image
          results_list.append(results)
      else:
          box_cls = pred_logits[-1]
          box_pred = pred_bboxes[-1]
          results_list = self.inference(box_cls, box_pred, cfg, device)
      if rescale:
          results_list = self.do_results_post_process(
              results_list, cfg, batch_img_metas=batch_img_metas
          )
      return results_list
  
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 10 for calling the DynamicDiffusionDetHead obj's underlying member method code with example usage: obj.predict_by_feat(x, time_pairs, batch_noise_bboxes, batch_noise_bboxes_raw, batch_image_size, device, batch_img_metas, cfg, rescale) and returns: results_list