code: def infer_dataset_task(
      task: str, dataset_cfg: Config, var_name: Optional[str] = None
  ) -> str:
      """Try to infer the dataset's task type from the config and the variable
      name."""
      if task != "auto":
          return task
  
      if dataset_cfg.pipeline is not None:
          if dataset_cfg.pipeline[-1].type == "PackTextDetInputs":
              return "textdet"
          elif dataset_cfg.pipeline[-1].type == "PackTextRecogInputs":
              return "textrecog"
  
      if var_name is not None:
          if "det" in var_name:
              return "textdet"
          elif "rec" in var_name:
              return "textrecog"
  
      raise ValueError(
          "Unable to infer the task type from dataset pipeline "
          "or variable name. Please specify the task type with --task argument "
          "explicitly."
      )
  
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 4 for calling a global function with example usage: infer_dataset_task(task, dataset_cfg, var_name) and returns: task, str, str, str, str