class_docstr: MMOCR Inferencer. It's a wrapper around three base task
  inferenecers: TextDetInferencer, TextRecInferencer and KIEInferencer,
  and it can be used to perform end-to-end OCR or KIE inference.
  
  Args:
      det (Optional[Union[ConfigType, str]]): Pretrained text detection
          algorithm. It's the path to the config file or the model name
          defined in metafile. Defaults to None.
      det_weights (Optional[str]): Path to the custom checkpoint file of
          the selected det model. If it is not specified and "det" is a model
          name of metafile, the weights will be loaded from metafile.
          Defaults to None.
      rec (Optional[Union[ConfigType, str]]): Pretrained text recognition
          algorithm. It's the path to the config file or the model name
          defined in metafile. Defaults to None.
      rec_weights (Optional[str]): Path to the custom checkpoint file of
          the selected rec model. If it is not specified and "rec" is a model
          name of metafile, the weights will be loaded from metafile.
          Defaults to None.
      kie (Optional[Union[ConfigType, str]]): Pretrained key information
          extraction algorithm. It's the path to the config file or the model
          name defined in metafile. Defaults to None.
      kie_weights (Optional[str]): Path to the custom checkpoint file of
          the selected kie model. If it is not specified and "kie" is a model
          name of metafile, the weights will be loaded from metafile.
          Defaults to None.
      device (Optional[str]): Device to run inference. If None, the available
          device will be automatically used. Defaults to None.
docstr: Process the predictions and visualization results from ``forward``
  and ``visualize``.
  
  This method should be responsible for the following tasks:
  
  1. Convert datasamples into a json-serializable dict if needed.
  2. Pack the predictions and visualization results and return them.
  3. Dump or log the predictions.
  
  Args:
      preds (PredType): Predictions of the model.
      visualization (Optional[np.ndarray]): Visualized predictions.
      print_result (bool): Whether to print the result.
          Defaults to False.
      save_pred (bool): Whether to save the inference result. Defaults to
          False.
      pred_out_dir: File to save the inference results w/o
          visualization. If left as empty, no file will be saved.
          Defaults to ''.
  
  Returns:
      Dict: Inference and visualization results, mapped from
          "predictions" and "visualization".
docstr_tok: ["Process","the","predictions","and","visualization","results","from","``","forward","``","and","``","visualize","``",".","This","method","should","be","responsible","for","the","following","tasks",":","1",".","Convert","datasamples","into","a","json-serializable","dict","if","needed",".","2",".","Pack","the","predictions","and","visualization","results","and","return","them",".","3",".","Dump","or","log","the","predictions",".","Args",":","preds","(","PredType",")",":","Predictions","of","the","model",".","visualization","(","Optional","[","np.ndarray","]",")",":","Visualized","predictions",".","print_result","(","bool",")",":","Whether","to","print","the","result",".","Defaults","to","False",".","save_pred","(","bool",")",":","Whether","to","save","the","inference","result",".","Defaults","to","False",".","pred_out_dir",":","File","to","save","the","inference","results","w\/o","visualization",".","If","left","as","empty",",","no","file","will","be","saved",".","Defaults","to","``",".","Returns",":","Dict",":","Inference","and","visualization","results",",","mapped","from","``","predictions","''","and","``","visualization","''","."]
code: def postprocess(
      self,
      preds: PredType,
      visualization: Optional[List[np.ndarray]] = None,
      print_result: bool = False,
      save_pred: bool = False,
      pred_out_dir: str = "",
  ) -> Union[ResType, Tuple[ResType, np.ndarray]]:
      """Process the predictions and visualization results from ``forward``
      and ``visualize``.
  
      This method should be responsible for the following tasks:
  
      1. Convert datasamples into a json-serializable dict if needed.
      2. Pack the predictions and visualization results and return them.
      3. Dump or log the predictions.
  
      Args:
          preds (PredType): Predictions of the model.
          visualization (Optional[np.ndarray]): Visualized predictions.
          print_result (bool): Whether to print the result.
              Defaults to False.
          save_pred (bool): Whether to save the inference result. Defaults to
              False.
          pred_out_dir: File to save the inference results w/o
              visualization. If left as empty, no file will be saved.
              Defaults to ''.
  
      Returns:
          Dict: Inference and visualization results, mapped from
              "predictions" and "visualization".
      """
  
      result_dict = {}
      pred_results = [
          {} for _ in range(len(next(iter(preds.values()))))
      ]
      if "rec" in self.mode:
          for i, rec_pred in enumerate(preds["rec"]):
              result = dict(rec_texts=[], rec_scores=[])
              for rec_pred_instance in rec_pred:
                  rec_dict_res = self.textrec_inferencer.pred2dict(
                      rec_pred_instance
                  )
                  result["rec_texts"].append(rec_dict_res["text"])
                  result["rec_scores"].append(rec_dict_res["scores"])
              pred_results[i].update(result)
      if "det" in self.mode:
          for i, det_pred in enumerate(preds["det"]):
              det_dict_res = self.textdet_inferencer.pred2dict(det_pred)
              pred_results[i].update(
                  dict(
                      det_polygons=det_dict_res["polygons"],
                      det_scores=det_dict_res["scores"],
                  )
              )
      if "kie" in self.mode:
          for i, kie_pred in enumerate(preds["kie"]):
              kie_dict_res = self.kie_inferencer.pred2dict(kie_pred)
              pred_results[i].update(
                  dict(
                      kie_labels=kie_dict_res["labels"],
                      kie_scores=kie_dict_res["scores"],
                  ),
                  kie_edge_scores=kie_dict_res["edge_scores"],
                  kie_edge_labels=kie_dict_res["edge_labels"],
              )
  
      if save_pred and pred_out_dir:
          pred_key = "det" if "det" in self.mode else "rec"
          for pred, pred_result in zip(preds[pred_key], pred_results):
              img_path = (
                  pred.img_path
                  if pred_key == "det"
                  else pred[0].img_path
              )
              pred_name = osp.splitext(osp.basename(img_path))[0]
              pred_name = f"{pred_name}.json"
              pred_out_file = osp.join(pred_out_dir, pred_name)
              mmengine.dump(
                  pred_result, pred_out_file, ensure_ascii=False
              )
  
      result_dict["predictions"] = pred_results
      if print_result:
          print(result_dict)
      result_dict["visualization"] = visualization
      return result_dict
  
imports: import os.path
  from datetime import datetime
  from typing import Dict, List, Optional, Tuple, Union
  import mmcv
  import mmengine
  import numpy
  from rich.progress import track
  from mmocr.registry import VISUALIZERS
  from mmocr.structures import TextSpottingDataSample
  from mmocr.utils import ConfigType, bbox2poly, crop_img, poly2bbox
  from .base_mmocr_inferencer import BaseMMOCRInferencer, InputsType, PredType, ResType
  from .kie_inferencer import KIEInferencer
  from .textdet_inferencer import TextDetInferencer
  from .textrec_inferencer import TextRecInferencer
label_desc: Use image node_id 6 for calling the MMOCRInferencer obj's underlying member method code with example usage: obj.postprocess(preds, visualization, print_result, save_pred, pred_out_dir) and returns: result_dict