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: Forward the inputs to the model.
  
  Args:
      inputs (InputsType): The inputs to be forwarded.
      batch_size (int): Batch size. Defaults to 1.
      det_batch_size (Optional[int]): Batch size for text detection
          model. Overwrite batch_size if it is not None.
          Defaults to None.
      rec_batch_size (Optional[int]): Batch size for text recognition
          model. Overwrite batch_size if it is not None.
          Defaults to None.
      kie_batch_size (Optional[int]): Batch size for KIE model.
          Overwrite batch_size if it is not None.
          Defaults to None.
  
  Returns:
      Dict: The prediction results. Possibly with keys "det", "rec", and
      "kie"..
docstr_tok: ["Forward","the","inputs","to","the","model",".","Args",":","inputs","(","InputsType",")",":","The","inputs","to","be","forwarded",".","batch_size","(","int",")",":","Batch","size",".","Defaults","to","1.","det_batch_size","(","Optional","[","int","]",")",":","Batch","size","for","text","detection","model",".","Overwrite","batch_size","if","it","is","not","None",".","Defaults","to","None",".","rec_batch_size","(","Optional","[","int","]",")",":","Batch","size","for","text","recognition","model",".","Overwrite","batch_size","if","it","is","not","None",".","Defaults","to","None",".","kie_batch_size","(","Optional","[","int","]",")",":","Batch","size","for","KIE","model",".","Overwrite","batch_size","if","it","is","not","None",".","Defaults","to","None",".","Returns",":","Dict",":","The","prediction","results",".","Possibly","with","keys","``","det","''",",","``","rec","''",",","and","``","kie","''",".."]
code: def forward(
      self,
      inputs: InputsType,
      batch_size: int = 1,
      det_batch_size: Optional[int] = None,
      rec_batch_size: Optional[int] = None,
      kie_batch_size: Optional[int] = None,
      **forward_kwargs,
  ) -> PredType:
      """Forward the inputs to the model.
  
      Args:
          inputs (InputsType): The inputs to be forwarded.
          batch_size (int): Batch size. Defaults to 1.
          det_batch_size (Optional[int]): Batch size for text detection
              model. Overwrite batch_size if it is not None.
              Defaults to None.
          rec_batch_size (Optional[int]): Batch size for text recognition
              model. Overwrite batch_size if it is not None.
              Defaults to None.
          kie_batch_size (Optional[int]): Batch size for KIE model.
              Overwrite batch_size if it is not None.
              Defaults to None.
  
      Returns:
          Dict: The prediction results. Possibly with keys "det", "rec", and
          "kie"..
      """
      result = {}
      forward_kwargs["progress_bar"] = False
      if det_batch_size is None:
          det_batch_size = batch_size
      if rec_batch_size is None:
          rec_batch_size = batch_size
      if kie_batch_size is None:
          kie_batch_size = batch_size
      if self.mode == "rec":
          # The extra list wrapper here is for the ease of postprocessing
          self.rec_inputs = inputs
          predictions = self.textrec_inferencer(
              self.rec_inputs,
              return_datasamples=True,
              batch_size=rec_batch_size,
              **forward_kwargs,
          )["predictions"]
          result["rec"] = [[p] for p in predictions]
      elif self.mode.startswith("det"):  # 'det'/'det_rec'/'det_rec_kie'
          result["det"] = self.textdet_inferencer(
              inputs,
              return_datasamples=True,
              batch_size=det_batch_size,
              **forward_kwargs,
          )["predictions"]
          if self.mode.startswith("det_rec"):  # 'det_rec'/'det_rec_kie'
              result["rec"] = []
              for img, det_data_sample in zip(
                  self._inputs2ndarrray(inputs), result["det"]
              ):
                  det_pred = det_data_sample.pred_instances
                  self.rec_inputs = []
                  for polygon in det_pred["polygons"]:
                      # Roughly convert the polygon to a quadangle with
                      # 4 points
                      quad = bbox2poly(poly2bbox(polygon)).tolist()
                      self.rec_inputs.append(crop_img(img, quad))
                  result["rec"].append(
                      self.textrec_inferencer(
                          self.rec_inputs,
                          return_datasamples=True,
                          batch_size=rec_batch_size,
                          **forward_kwargs,
                      )["predictions"]
                  )
              if self.mode == "det_rec_kie":
                  self.kie_inputs = []
                  # TODO: when the det output is empty, kie will fail
                  # as no gt-instances can be provided. It's a known
                  # issue but cannot be solved elegantly since we support
                  # batch inference.
                  for img, det_data_sample, rec_data_samples in zip(
                      inputs, result["det"], result["rec"]
                  ):
                      det_pred = det_data_sample.pred_instances
                      kie_input = dict(img=img)
                      kie_input["instances"] = []
                      for polygon, rec_data_sample in zip(
                          det_pred["polygons"], rec_data_samples
                      ):
                          kie_input["instances"].append(
                              dict(
                                  bbox=poly2bbox(polygon),
                                  text=rec_data_sample.pred_text.item,
                              )
                          )
                      self.kie_inputs.append(kie_input)
                  result["kie"] = self.kie_inferencer(
                      self.kie_inputs,
                      return_datasamples=True,
                      batch_size=kie_batch_size,
                      **forward_kwargs,
                  )["predictions"]
      return result
  
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 3 for calling the MMOCRInferencer obj's underlying member method code with example usage: obj.forward(inputs, batch_size, det_batch_size, rec_batch_size, kie_batch_size) and returns: result