code: def convert_d2_pred_to_datasample(
      data_samples: SampleList, d2_results_list: list
  ) -> SampleList:
      """Convert the Detectron2's result to DetDataSample.
  
      Args:
          data_samples (list[:obj:`DetDataSample`]): The batch
              data samples. It usually includes information such
              as `gt_instance` or `gt_panoptic_seg` or `gt_sem_seg`.
          d2_results_list (list): The list of the results of Detectron2's model.
  
      Returns:
          list[:obj:`DetDataSample`]: Detection results of the
          input images. Each DetDataSample usually contain
          'pred_instances'. And the ``pred_instances`` usually
          contains following keys.
  
          - scores (Tensor): Classification scores, has a shape
            (num_instance, )
          - labels (Tensor): Labels of bboxes, has a shape
            (num_instances, ).
          - bboxes (Tensor): Has a shape (num_instances, 4),
            the last dimension 4 arrange as (x1, y1, x2, y2).
      """
      assert len(data_samples) == len(d2_results_list)
      for data_sample, d2_results in zip(data_samples, d2_results_list):
          d2_instance = d2_results["instances"]
  
          results = InstanceData()
          results.bboxes = d2_instance.pred_boxes.tensor
          results.scores = d2_instance.scores
          results.labels = d2_instance.pred_classes
  
          if d2_instance.has("pred_masks"):
              results.masks = d2_instance.pred_masks
          data_sample.pred_instances = results
  
      return data_samples
  
imports: from typing import Union
  from mmengine.config import ConfigDict
  from mmengine.structures import InstanceData
  from torch import Tensor
  from mmdet.registry import MODELS
  from mmdet.structures import SampleList
  from mmdet.structures.bbox import BaseBoxes
  from mmdet.structures.mask import BitmapMasks, PolygonMasks
  from mmdet.utils import ConfigType
  from .base import BaseDetector
label_desc: Use image node_id 2 for calling a global function with example usage: convert_d2_pred_to_datasample(data_samples, d2_results_list) and returns: data_samples