docstr: Run after every testing iterations.
  
  Args:
      runner (:obj:`Runner`): The runner of the testing process.
      batch_idx (int): The index of the current batch in the val loop.
      data_batch (dict): Data from dataloader.
      outputs (Sequence[:obj:`DetDataSample`]): A batch of data samples
          that contain annotations and predictions.
docstr_tok: ["Run","after","every","testing","iterations",".","Args",":","runner","(",":","obj",":","`","Runner","`",")",":","The","runner","of","the","testing","process",".","batch_idx","(","int",")",":","The","index","of","the","current","batch","in","the","val","loop",".","data_batch","(","dict",")",":","Data","from","dataloader",".","outputs","(","Sequence","[",":","obj",":","`","DetDataSample","`","]",")",":","A","batch","of","data","samples","that","contain","annotations","and","predictions","."]
code: def after_test_iter(
      self,
      runner: Runner,
      batch_idx: int,
      data_batch: dict,
      outputs: Sequence[DetDataSample],
  ) -> None:
      """Run after every testing iterations.
  
      Args:
          runner (:obj:`Runner`): The runner of the testing process.
          batch_idx (int): The index of the current batch in the val loop.
          data_batch (dict): Data from dataloader.
          outputs (Sequence[:obj:`DetDataSample`]): A batch of data samples
              that contain annotations and predictions.
      """
      if self.draw is False:
          return
  
      if self.test_out_dir is not None:
          self.test_out_dir = osp.join(
              runner.work_dir, runner.timestamp, self.test_out_dir
          )
          mkdir_or_exist(self.test_out_dir)
  
      for data_sample in outputs:
          data_sample = data_sample.cpu()
  
          self._test_index += 1
  
          img_path = data_sample.img_path
          img_bytes = get(img_path, backend_args=self.backend_args)
          img = mmcv.imfrombytes(img_bytes, channel_order="rgb")
  
          out_file = None
          if self.test_out_dir is not None:
              out_file = osp.basename(img_path)
              out_file = osp.join(self.test_out_dir, out_file)
  
          text = data_sample.text
          if isinstance(text, str):  # VG
              gt_instances = data_sample.gt_instances
              tokens_positive = data_sample.tokens_positive
              if "phrase_ids" in data_sample:
                  # flickr30k
                  gt_labels = data_sample.phrase_ids
              else:
                  gt_labels = gt_instances.labels
              gt_bboxes = gt_instances.get("bboxes", None)
              if gt_bboxes is not None and isinstance(
                  gt_bboxes, BaseBoxes
              ):
                  gt_instances.bboxes = gt_bboxes.tensor
              print(gt_labels, tokens_positive, gt_bboxes, img_path)
              pred_instances = data_sample.pred_instances
              pred_instances = pred_instances[
                  pred_instances.scores > self.score_thr
              ]
              pred_labels = pred_instances.labels
              pred_bboxes = pred_instances.bboxes
              pred_scores = pred_instances.scores
  
              max_label = 0
              if len(gt_labels) > 0:
                  max_label = max(gt_labels)
              if len(pred_labels) > 0:
                  max_label = max(max(pred_labels), max_label)
  
              max_label = int(max(max_label, 0))
              palette = np.random.randint(
                  0, 256, size=(max_label + 1, 3)
              )
              bbox_palette = [tuple(c) for c in palette]
              # bbox_palette = get_palette('random', max_label + 1)
              if len(gt_labels) >= len(pred_labels):
                  colors = [bbox_palette[label] for label in gt_labels]
              else:
                  colors = [
                      bbox_palette[label] for label in pred_labels
                  ]
  
              self._visualizer.set_image(img)
  
              for label, bbox, color in zip(
                  gt_labels, gt_bboxes, colors
              ):
                  self._visualizer.draw_bboxes(
                      bbox,
                      edge_colors=color,
                      face_colors=color,
                      alpha=0.3,
                  )
                  self._visualizer.draw_bboxes(
                      bbox, edge_colors=color, alpha=1
                  )
  
              drawn_img = self._visualizer.get_image()
  
              new_image = (
                  np.ones((100, img.shape[1], 3), dtype=np.uint8) * 255
              )
              self._visualizer.set_image(new_image)
  
              if tokens_positive == -1:  # REC
                  gt_tokens_positive = [[]]
              else:  # Phrase Grounding
                  gt_tokens_positive = [
                      tokens_positive[label] for label in gt_labels
                  ]
              split_by_character = [char for char in text]
              characters = []
              start_index = 0
              end_index = 0
              for w in split_by_character:
                  end_index += len(w)
                  is_find = False
                  for i, positive in enumerate(gt_tokens_positive):
                      for p in positive:
                          if start_index >= p[0] and end_index <= p[1]:
                              characters.append([w, colors[i]])
                              is_find = True
                              break
                      if is_find:
                          break
                  if not is_find:
                      characters.append([w, (0, 0, 0)])
                  start_index = end_index
  
              drawn_text = draw_all_character(
                  self._visualizer, characters, img.shape[1]
              )
              drawn_gt_img = np.concatenate(
                  (drawn_img, drawn_text), axis=0
              )
  
              self._visualizer.set_image(img)
  
              for label, bbox, color in zip(
                  pred_labels, pred_bboxes, colors
              ):
                  self._visualizer.draw_bboxes(
                      bbox,
                      edge_colors=color,
                      face_colors=color,
                      alpha=0.3,
                  )
                  self._visualizer.draw_bboxes(
                      bbox, edge_colors=color, alpha=1
                  )
              print(pred_labels, pred_bboxes, pred_scores, colors)
              areas = (pred_bboxes[:, 3] - pred_bboxes[:, 1]) * (
                  pred_bboxes[:, 2] - pred_bboxes[:, 0]
              )
              scales = _get_adaptive_scales(areas)
              score = [str(round(s.item(), 2)) for s in pred_scores]
              font_sizes = [
                  int(13 * scales[i]) for i in range(len(scales))
              ]
              self._visualizer.draw_texts(
                  score,
                  pred_bboxes[:, :2].int(),
                  colors=(255, 255, 255),
                  font_sizes=font_sizes,
                  bboxes=[
                      {
                          "facecolor": "black",
                          "alpha": 0.8,
                          "pad": 0.7,
                          "edgecolor": "none",
                      }
                  ]
                  * len(pred_bboxes),
              )
  
              drawn_img = self._visualizer.get_image()
  
              new_image = (
                  np.ones((100, img.shape[1], 3), dtype=np.uint8) * 255
              )
              self._visualizer.set_image(new_image)
              drawn_text = draw_all_character(
                  self._visualizer, characters, img.shape[1]
              )
              drawn_pred_img = np.concatenate(
                  (drawn_img, drawn_text), axis=0
              )
              drawn_img = np.concatenate(
                  (drawn_gt_img, drawn_pred_img), axis=1
              )
  
              if self.show:
                  self._visualizer.show(
                      drawn_img,
                      win_name=osp.basename(img_path),
                      wait_time=self.wait_time,
                  )
              if out_file is not None:
                  mmcv.imwrite(drawn_img[..., ::-1], out_file)
              else:
                  self.add_image(
                      "test_img", drawn_img, self._test_index
                  )
          else:  # OD
              self._visualizer.add_datasample(
                  osp.basename(img_path) if self.show else "test_img",
                  img,
                  data_sample=data_sample,
                  show=self.show,
                  wait_time=self.wait_time,
                  pred_score_thr=self.score_thr,
                  out_file=out_file,
                  step=self._test_index,
              )
  
imports: import os.path
  import warnings
  from typing import Optional, Sequence
  import mmcv
  import numpy
  from mmengine.fileio import get
  from mmengine.hooks import Hook
  from mmengine.runner import Runner
  from mmengine.utils import mkdir_or_exist
  from mmengine.visualization import Visualizer
  from mmdet.datasets.samplers import TrackImgSampler
  from mmdet.registry import HOOKS
  from mmdet.structures import DetDataSample, TrackDataSample
  from mmdet.structures.bbox import BaseBoxes
  from mmdet.visualization.palette import _get_adaptive_scales
label_desc: Use image node_id 1 for calling the GroundingVisualizationHook obj's underlying member method code with example usage: obj.after_test_iter(runner, batch_idx, data_batch, outputs) without return types