code: def test_add_datasample(self):
      h = 12
      w = 10
      num_class = 3
      num_bboxes = 5
      out_file = "out_file.jpg"
  
      image = np.random.randint(0, 256, size=(h, w, 3)).astype("uint8")
  
      # test gt_instances
      gt_instances = InstanceData()
      gt_instances.bboxes = _rand_bboxes(num_bboxes, h, w)
      gt_instances.labels = torch.randint(0, num_class, (num_bboxes,))
      det_data_sample = DetDataSample()
      det_data_sample.gt_instances = gt_instances
  
      det_local_visualizer = DetLocalVisualizer()
      det_local_visualizer.add_datasample(
          "image", image, det_data_sample, draw_pred=False
      )
  
      # test out_file
      det_local_visualizer.add_datasample(
          "image",
          image,
          det_data_sample,
          draw_pred=False,
          out_file=out_file,
      )
      assert os.path.exists(out_file)
      drawn_img = cv2.imread(out_file)
      assert drawn_img.shape == (h, w, 3)
      os.remove(out_file)
  
      # test gt_instances and pred_instances
      pred_instances = InstanceData()
      pred_instances.bboxes = _rand_bboxes(num_bboxes, h, w)
      pred_instances.labels = torch.randint(0, num_class, (num_bboxes,))
      pred_instances.scores = torch.rand((num_bboxes,))
      det_data_sample.pred_instances = pred_instances
  
      det_local_visualizer.add_datasample(
          "image", image, det_data_sample, out_file=out_file
      )
      self._assert_image_and_shape(out_file, (h, w * 2, 3))
  
      det_local_visualizer.add_datasample(
          "image",
          image,
          det_data_sample,
          draw_gt=False,
          out_file=out_file,
      )
      self._assert_image_and_shape(out_file, (h, w, 3))
  
      det_local_visualizer.add_datasample(
          "image",
          image,
          det_data_sample,
          draw_pred=False,
          out_file=out_file,
      )
      self._assert_image_and_shape(out_file, (h, w, 3))
  
      # test gt_panoptic_seg and pred_panoptic_seg
      det_local_visualizer.dataset_meta = dict(classes=("1", "2"))
      gt_sem_seg = _create_panoptic_data(num_bboxes, h, w)
      panoptic_seg = PixelData(sem_seg=gt_sem_seg)
  
      det_data_sample = DetDataSample()
      det_data_sample.gt_panoptic_seg = panoptic_seg
  
      pred_sem_seg = _create_panoptic_data(num_bboxes, h, w)
      panoptic_seg = PixelData(sem_seg=pred_sem_seg)
      det_data_sample.pred_panoptic_seg = panoptic_seg
  
      det_local_visualizer.add_datasample(
          "image", image, det_data_sample, out_file=out_file
      )
      self._assert_image_and_shape(out_file, (h, w * 2, 3))
  
      # class information must be provided
      det_local_visualizer.dataset_meta = {}
      with self.assertRaises(AssertionError):
          det_local_visualizer.add_datasample(
              "image", image, det_data_sample, out_file=out_file
          )
  
imports: import os
  from unittest import TestCase
  import cv2
  import numpy
  import torch
  from mmengine.structures import InstanceData, PixelData
  from mmdet.evaluation import INSTANCE_OFFSET
  from mmdet.structures import DetDataSample
  from mmdet.visualization import DetLocalVisualizer, TrackLocalVisualizer
label_desc: Use image node_id 1 for calling the TestDetLocalVisualizer obj's underlying member method code with example usage: obj.test_add_datasample() without return types