MMOCRInferencer¶
- class mmocr.apis.inferencers.MMOCRInferencer(det=None, det_weights=None, rec=None, rec_weights=None, kie=None, kie_weights=None, device=None)[源代码]¶
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.
- 参数
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.
- 返回类型
- forward(inputs, batch_size=1, det_batch_size=None, rec_batch_size=None, kie_batch_size=None, **forward_kwargs)[源代码]¶
Forward the inputs to the model.
- 参数
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.
- 返回
The prediction results. Possibly with keys “det”, “rec”, and “kie”..
- 返回类型
Dict
- postprocess(preds, visualization=None, print_result=False, save_pred=False, pred_out_dir='')[源代码]¶
Process the predictions and visualization results from
forward
andvisualize
.This method should be responsible for the following tasks:
Convert datasamples into a json-serializable dict if needed.
Pack the predictions and visualization results and return them.
Dump or log the predictions.
- 参数
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 ‘’.
- 返回
- Inference and visualization results, mapped from
”predictions” and “visualization”.
- 返回类型
Dict
- visualize(inputs, preds, **kwargs)[源代码]¶
Visualize predictions.
- 参数
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 visualization results only if applicable.
- 返回类型
List[np.ndarray] or None