code: def main():
      args = parse_args()
      cfg = Config.fromfile(args.config)
      if args.cfg_options is not None:
          cfg.merge_from_dict(args.cfg_options)
  
      init_default_scope(cfg.get("default_scope", "mmocr"))
  
      dataset_cfg, visualizer_cfg = obtain_dataset_cfg(
          cfg, args.phase, args.mode, args.task
      )
      dataset = DATASETS.build(dataset_cfg)
      visualizer = VISUALIZERS.build(visualizer_cfg)
      visualizer.dataset_meta = dataset.metainfo
  
      intermediate_imgs = []
  
      if dataset_cfg.type == "ConcatDataset":
          for sub_dataset in dataset.datasets:
              sub_dataset.pipeline = InspectCompose(
                  sub_dataset.pipeline.transforms, intermediate_imgs
              )
      else:
          dataset.pipeline = InspectCompose(
              dataset.pipeline.transforms, intermediate_imgs
          )
  
      # init visualization image number
      assert args.show_number > 0
      display_number = min(args.show_number, len(dataset))
  
      progress_bar = ProgressBar(display_number)
      # fetching items from dataset is a must for visualization
      for i, _ in zip(range(display_number), dataset):
          image_i = []
          result_i = [
              result["dataset_sample"] for result in intermediate_imgs
          ]
          for k, datasample in enumerate(result_i):
              image = datasample.img
              if len(image.shape) == 3:
                  image = image[..., [2, 1, 0]]  # bgr to rgb
              image_show = visualizer.add_datasample(
                  "result",
                  image,
                  datasample,
                  draw_pred=False,
                  draw_gt=True,
                  show=False,
              )
              image_i.append(image_show)
  
          if args.mode == "pipeline":
              image = make_grid(image_i, intermediate_imgs)
          else:
              image = image_i[-1]
  
          if hasattr(datasample, "img_path"):
              filename = osp.basename(datasample.img_path)
          else:
              # some dataset have not image path
              filename = f"{i}.jpg"
          out_file = (
              osp.join(args.output_dir, filename)
              if args.output_dir is not None
              else None
          )
  
          if out_file is not None:
              mmcv.imwrite(image[..., ::-1], out_file)
  
          if not args.not_show:
              visualizer.show(
                  image, win_name=filename, wait_time=args.show_interval
              )
  
          intermediate_imgs.clear()
          progress_bar.update()
  
imports: import argparse
  import os.path
  import sys
  from typing import Optional, Tuple
  import cv2
  import mmcv
  import numpy
  from mmengine.config import Config, DictAction
  from mmengine.dataset import Compose
  from mmengine.registry import init_default_scope
  from mmengine.utils import ProgressBar
  from mmengine.visualization import Visualizer
  from mmocr.registry import DATASETS, VISUALIZERS
label_desc: Use image node_id 6 for calling a global function with example usage: main() without return types