code: def visualize(
      self,
      inputs: InputsType,
      preds: PredType,
      return_vis: bool = False,
      show: bool = False,
      wait_time: int = 0,
      draw_pred: bool = True,
      pred_score_thr: float = 0.3,
      no_save_vis: bool = False,
      img_out_dir: str = "",
      **kwargs,
  ) -> Union[List[np.ndarray], None]:
      if no_save_vis is True:
          img_out_dir = ""
  
      if not show and img_out_dir == "" and not return_vis:
          return None
  
      if self.visualizer is None:
          raise ValueError(
              'Visualization needs the "visualizer" term'
              "defined in the config, but got None."
          )
  
      results = []
  
      text_cfg = self.DEFAULT_TEXT_CFG
  
      for single_input, pred in zip(inputs, preds):
          if isinstance(single_input, str):
              img_bytes = mmengine.fileio.get(single_input)
              img = mmcv.imfrombytes(img_bytes)
              img = img[:, :, ::-1]
              img_name = osp.basename(single_input)
          elif isinstance(single_input, np.ndarray):
              img = single_input.copy()
              img_num = str(self.num_visualized_imgs).zfill(8)
              img_name = f"{img_num}.jpg"
          else:
              raise ValueError(
                  "Unsupported input type: " f"{type(single_input)}"
              )
  
          out_file = (
              osp.join(img_out_dir, "vis", img_name)
              if img_out_dir != ""
              else None
          )
  
          self.visualizer.set_image(img)
  
          img_scale = get_adaptive_scale(img.shape[:2])
          text_cfg["font_sizes"] = int(img_scale * 7)
  
          self.visualizer.draw_texts(
              pred.pred_caption,
              torch.tensor([img_scale * 5, img_scale * 5]),
              **text_cfg,
          )
          drawn_img = self.visualizer.get_image()
  
          self.visualizer.add_datasample(
              img_name,
              drawn_img,
              pred,
              show=show,
              wait_time=wait_time,
              draw_gt=False,
              draw_pred=draw_pred,
              pred_score_thr=pred_score_thr,
              out_file=out_file,
          )
          results.append(self.visualizer.get_image())
          self.num_visualized_imgs += 1
  
      return results
  
file_path: mmdetection/projects/XDecoder/xdecoder/inference/image_caption.py
imports: import copy
  import os.path
  from typing import Iterable, List, Optional, Tuple, Union
  import mmcv
  import mmengine
  import numpy
  import torch
  from mmengine.dataset import Compose
  from rich.progress import track
  from mmdet.apis.det_inferencer import DetInferencer, InputsType, PredType
  from mmdet.utils import ConfigType
label_desc: Use image node_id 1 for calling the ImageCaptionInferencer obj's underlying member method code with example usage: obj.visualize(inputs, preds, return_vis, show, wait_time, draw_pred, pred_score_thr, no_save_vis, img_out_dir) and returns: results, None