Shortcuts

MMOCRInferencer

class mmocr.apis.inferencers.MMOCRInferencer(det=None, det_weights=None, rec=None, rec_weights=None, kie=None, kie_weights=None, device=None)[source]

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.

Parameters
  • 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.

Return type

None

forward(inputs, batch_size=1, det_batch_size=None, rec_batch_size=None, kie_batch_size=None, **forward_kwargs)[source]

Forward the inputs to the model.

Parameters
  • 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

The prediction results. Possibly with keys “det”, “rec”, and “kie”..

Return type

Dict

postprocess(preds, visualization=None, print_result=False, save_pred=False, pred_out_dir='')[source]

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.

Parameters
  • 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 (str) – File to save the inference results w/o visualization. If left as empty, no file will be saved. Defaults to ‘’.

Returns

Inference and visualization results, mapped from

”predictions” and “visualization”.

Return type

Dict

visualize(inputs, preds, **kwargs)[source]

Visualize predictions.

Parameters
  • inputs (List[Union[str, np.ndarray]]) – Inputs for the inferencer.

  • preds (List[Dict]) – Predictions of the model.

  • 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

Returns visualization results only if applicable.

Return type

List[np.ndarray] or None

Read the Docs v: dev-1.x
Versions
latest
stable
v1.0.1
v1.0.0
0.x
v0.6.3
v0.6.2
v0.6.1
v0.6.0
v0.5.0
v0.4.1
v0.4.0
v0.3.0
v0.2.1
v0.2.0
v0.1.0
dev-1.x
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.