class_docstr: Key Information Extraction Inferencer.
  
  Args:
      model (str, optional): Path to the config file or the model name
          defined in metafile. For example, it could be
          "sdmgr_unet16_60e_wildreceipt" or
          "configs/kie/sdmgr/sdmgr_unet16_60e_wildreceipt.py".
          If model is not specified, user must provide the
          `weights` saved by MMEngine which contains the config string.
          Defaults to None.
      weights (str, optional): Path to the checkpoint. If it is not specified
          and model is a model name of metafile, the weights will be loaded
          from metafile. Defaults to None.
      device (str, optional): Device to run inference. If None, the available
          device will be automatically used. Defaults to None.
      scope (str, optional): The scope of the model. Defaults to "mmocr".
class_docstr_tok: ["Key","Information","Extraction","Inferencer",".","Args",":","model","(","str",",","optional",")",":","Path","to","the","config","file","or","the","model","name","defined","in","metafile",".","For","example",",","it","could","be","``","sdmgr_unet16_60e_wildreceipt","''","or","``","configs\/kie\/sdmgr\/sdmgr_unet16_60e_wildreceipt.py","''",".","If","model","is","not","specified",",","user","must","provide","the","`","weights","`","saved","by","MMEngine","which","contains","the","config","string",".","Defaults","to","None",".","weights","(","str",",","optional",")",":","Path","to","the","checkpoint",".","If","it","is","not","specified","and","model","is","a","model","name","of","metafile",",","the","weights","will","be","loaded","from","metafile",".","Defaults","to","None",".","device","(","str",",","optional",")",":","Device","to","run","inference",".","If","None",",","the","available","device","will","be","automatically","used",".","Defaults","to","None",".","scope","(","str",",","optional",")",":","The","scope","of","the","model",".","Defaults","to","``","mmocr","''","."]
docstr: Visualize predictions.
  
  Args:
      inputs (List[Union[str, np.ndarray]]): Inputs for the inferencer.
      preds (List[Dict]): Predictions of the model.
      return_vis (bool): Whether to return the visualization result.
          Defaults to False.
      show (bool): Whether to display the image in a popup window.
          Defaults to False.
      wait_time (float): The interval of show (s). Defaults to 0.
      draw_pred (bool): Whether to draw predicted bounding boxes.
          Defaults to True.
      pred_score_thr (float): Minimum score of bboxes to draw.
          Defaults to 0.3.
      save_vis (bool): Whether to save the visualization result. Defaults
          to False.
      img_out_dir (str): Output directory of visualization results.
          If left as empty, no file will be saved. Defaults to ''.
  
  Returns:
      List[np.ndarray] or None: Returns visualization results only if
      applicable.
docstr_tok: ["Visualize","predictions",".","Args",":","inputs","(","List","[","Union","[","str",",","np.ndarray","]","]",")",":","Inputs","for","the","inferencer",".","preds","(","List","[","Dict","]",")",":","Predictions","of","the","model",".","return_vis","(","bool",")",":","Whether","to","return","the","visualization","result",".","Defaults","to","False",".","show","(","bool",")",":","Whether","to","display","the","image","in","a","popup","window",".","Defaults","to","False",".","wait_time","(","float",")",":","The","interval","of","show","(","s",")",".","Defaults","to","0.","draw_pred","(","bool",")",":","Whether","to","draw","predicted","bounding","boxes",".","Defaults","to","True",".","pred_score_thr","(","float",")",":","Minimum","score","of","bboxes","to","draw",".","Defaults","to","0.3.","save_vis","(","bool",")",":","Whether","to","save","the","visualization","result",".","Defaults","to","False",".","img_out_dir","(","str",")",":","Output","directory","of","visualization","results",".","If","left","as","empty",",","no","file","will","be","saved",".","Defaults","to","``",".","Returns",":","List","[","np.ndarray","]","or","None",":","Returns","visualization","results","only","if","applicable","."]
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,
      save_vis: bool = False,
      img_out_dir: str = "",
  ) -> Union[List[np.ndarray], None]:
      """Visualize predictions.
  
      Args:
          inputs (List[Union[str, np.ndarray]]): Inputs for the inferencer.
          preds (List[Dict]): Predictions of the model.
          return_vis (bool): Whether to return the visualization result.
              Defaults to False.
          show (bool): Whether to display the image in a popup window.
              Defaults to False.
          wait_time (float): The interval of show (s). Defaults to 0.
          draw_pred (bool): Whether to draw predicted bounding boxes.
              Defaults to True.
          pred_score_thr (float): Minimum score of bboxes to draw.
              Defaults to 0.3.
          save_vis (bool): Whether to save the visualization result. Defaults
              to False.
          img_out_dir (str): Output directory of visualization results.
              If left as empty, no file will be saved. Defaults to ''.
  
      Returns:
          List[np.ndarray] or None: Returns visualization results only if
          applicable.
      """
      if self.visualizer is None or not (
          show or save_vis or return_vis
      ):
          return None
  
      if getattr(self, "visualizer") is None:
          raise ValueError(
              'Visualization needs the "visualizer" term'
              "defined in the config, but got None."
          )
  
      results = []
  
      for single_input, pred in zip(inputs, preds):
          assert "img" in single_input or "img_shape" in single_input
          if "img" in single_input:
              if isinstance(single_input["img"], str):
                  img_bytes = mmengine.fileio.get(single_input["img"])
                  img = mmcv.imfrombytes(img_bytes, channel_order="rgb")
              elif isinstance(single_input["img"], np.ndarray):
                  img = single_input["img"].copy()[:, :, ::-1]  # To RGB
          elif "img_shape" in single_input:
              img = np.zeros(single_input["img_shape"], dtype=np.uint8)
          else:
              raise ValueError(
                  'Input does not contain either "img" or '
                  '"img_shape"'
              )
          img_name = osp.splitext(osp.basename(pred.img_path))[0]
  
          if save_vis and img_out_dir:
              out_file = osp.splitext(img_name)[0]
              out_file = f"{out_file}.jpg"
              out_file = osp.join(img_out_dir, out_file)
          else:
              out_file = None
  
          visualization = self.visualizer.add_datasample(
              img_name,
              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(visualization)
  
      return results
  
imports: import copy
  import os.path
  from typing import Any, Dict, List, Optional, Sequence, Union
  import mmcv
  import mmengine
  import numpy
  from mmengine.dataset import Compose, pseudo_collate
  from mmengine.runner.checkpoint import _load_checkpoint
  from mmocr.registry import DATASETS
  from mmocr.structures import KIEDataSample
  from mmocr.utils import ConfigType
  from .base_mmocr_inferencer import BaseMMOCRInferencer, ModelType, PredType
label_desc: Use image node_id 6 for calling the KIEInferencer obj's underlying member method code with example usage: obj.visualize(inputs, preds, return_vis, show, wait_time, draw_pred, pred_score_thr, save_vis, img_out_dir) and returns: results, None