class_docstr: Base inferencer.
  
  Args:
      model (str, optional): Path to the config file or the model name
          defined in metafile. For example, it could be
          "dbnet_resnet18_fpnc_1200e_icdar2015" or
          "configs/textdet/dbnet/dbnet_resnet18_fpnc_1200e_icdar2015.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: 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 (List[Dict]): Predictions of the model.
      visualization (Optional[np.ndarray]): Visualized predictions.
      return_datasample (bool): Whether to use Datasample to store
          inference results. If False, dict will be used.
      print_result (bool): Whether to print the inference result w/o
          visualization to the console. 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 with key ``predictions``
      and ``visualization``.
  
      - ``visualization`` (Any): Returned by :meth:`visualize`.
      - ``predictions`` (dict or DataSample): Returned by
          :meth:`forward` and processed in :meth:`postprocess`.
          If ``return_datasample=False``, it usually should be a
          json-serializable dict containing only basic data elements such
          as strings and numbers.
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","(","List","[","Dict","]",")",":","Predictions","of","the","model",".","visualization","(","Optional","[","np.ndarray","]",")",":","Visualized","predictions",".","return_datasample","(","bool",")",":","Whether","to","use","Datasample","to","store","inference","results",".","If","False",",","dict","will","be","used",".","print_result","(","bool",")",":","Whether","to","print","the","inference","result","w\/o","visualization","to","the","console",".","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","with","key","``","predictions","``","and","``","visualization","``",".","-","``","visualization","``","(","Any",")",":","Returned","by",":","meth",":","`","visualize","`",".","-","``","predictions","``","(","dict","or","DataSample",")",":","Returned","by",":","meth",":","`","forward","`","and","processed","in",":","meth",":","`","postprocess","`",".","If","``","return_datasample=False","``",",","it","usually","should","be","a","json-serializable","dict","containing","only","basic","data","elements","such","as","strings","and","numbers","."]
code: def postprocess(
      self,
      preds: PredType,
      visualization: Optional[List[np.ndarray]] = None,
      return_datasample: bool = False,
      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 (List[Dict]): Predictions of the model.
          visualization (Optional[np.ndarray]): Visualized predictions.
          return_datasample (bool): Whether to use Datasample to store
              inference results. If False, dict will be used.
          print_result (bool): Whether to print the inference result w/o
              visualization to the console. 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 with key ``predictions``
          and ``visualization``.
  
          - ``visualization`` (Any): Returned by :meth:`visualize`.
          - ``predictions`` (dict or DataSample): Returned by
              :meth:`forward` and processed in :meth:`postprocess`.
              If ``return_datasample=False``, it usually should be a
              json-serializable dict containing only basic data elements such
              as strings and numbers.
      """
      result_dict = {}
      results = preds
      if not return_datasample:
          results = []
          for pred in preds:
              result = self.pred2dict(pred)
              if save_pred and pred_out_dir:
                  pred_name = osp.splitext(osp.basename(pred.img_path))[
                      0
                  ]
                  pred_name = f"{pred_name}.json"
                  pred_out_file = osp.join(pred_out_dir, pred_name)
                  mmengine.dump(result, pred_out_file)
              results.append(result)
      # Add img to the results after printing and dumping
      result_dict["predictions"] = results
      if print_result:
          print(result_dict)
      result_dict["visualization"] = visualization
      return result_dict
  
imports: import os.path
  from typing import Dict, Iterable, List, Optional, Sequence, Tuple, Union
  import mmcv
  import mmengine
  import numpy
  from mmengine.dataset import Compose
  from mmengine.infer.infer import BaseInferencer, ModelType
  from mmengine.model.utils import revert_sync_batchnorm
  from mmengine.registry import init_default_scope
  from mmengine.structures import InstanceData
  from rich.progress import track
  from torch import Tensor
  from mmocr.utils import ConfigType
label_desc: Use image node_id 8 for calling the BaseMMOCRInferencer obj's underlying member method code with example usage: obj.postprocess(preds, visualization, return_datasample, print_result, save_pred, pred_out_dir) and returns: result_dict