OCR(文字识别)#

fastdeploy.vision.ocr.DBDetectorPreprocessor#

class fastdeploy.vision.ocr.DBDetectorPreprocessor[source]#

Create a preprocessor for DBDetectorModel

disable_normalize()[source]#

This function will disable normalize in preprocessing step.

disable_permute()[source]#

This function will disable hwc2chw in preprocessing step.

property max_side_len#

Get max_side_len value.

run(input_ims)#

Process input image

Param

input_ims: (list of numpy.ndarray) The input images

Returns

list of FDTensor

set_normalize(mean, std, is_scale)[source]#
Set preprocess normalize parameters, please call this API to

customize the normalize parameters, otherwise it will use the default normalize parameters.

Param

mean: (list of float) mean values

Param

std: (list of float) std values

Param

is_scale: (boolean) whether to scale

use_cuda(enable_cv_cuda=False, gpu_id=-1)#

Use CUDA processors

Param

enable_cv_cuda: Ture: use CV-CUDA, False: use CUDA only

Param

gpu_id: GPU device id

fastdeploy.vision.ocr.DBDetectorPostprocessor#

class fastdeploy.vision.ocr.DBDetectorPostprocessor[source]#

Create a postprocessor for DBDetectorModel

property det_db_box_thresh#

Return the det_db_box_thresh of DBDetectorPostprocessor

property det_db_score_mode#

Return the det_db_score_mode of DBDetectorPostprocessor

property det_db_thresh#

Return the det_db_thresh of DBDetectorPostprocessor

property det_db_unclip_ratio#

Return the det_db_unclip_ratio of DBDetectorPostprocessor

run(runtime_results, batch_det_img_info)[source]#

Postprocess the runtime results for DBDetectorModel

Param

runtime_results: (list of FDTensor or list of pyArray)The output FDTensor results from runtime

Param

batch_det_img_info: (list of std::array<int, 4>)The output of det_preprocessor

Returns

list of Result(If the runtime_results is predict by batched samples, the length of this list equals to the batch size)

property use_dilation#

Return the use_dilation of DBDetectorPostprocessor

fastdeploy.vision.ocr.DBDetector#

class fastdeploy.vision.ocr.DBDetector(model_file='', params_file='', runtime_option=None, model_format=<ModelFormat.PADDLE: 1>)[source]#

Load OCR detection model provided by PaddleOCR.

Parameters
  • model_file – (str)Path of model file, e.g ./ch_PP-OCRv3_det_infer/model.pdmodel.

  • params_file – (str)Path of parameter file, e.g ./ch_PP-OCRv3_det_infer/model.pdiparams, if the model format is ONNX, this parameter will be ignored.

  • runtime_option – (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it’s None, will use the default backend on CPU.

  • model_format – (fastdeploy.ModelForamt)Model format of the loaded model.

batch_predict(images)[source]#

Predict a batch of input image :param images: (list of numpy.ndarray) The input image list, each element is a 3-D array with layout HWC, BGR format :return: batch_boxes

clone()[source]#

Clone OCR detection model object

Returns

a new OCR detection model object

get_profile_time()#

Get profile time of Runtime after the profile process is done.

predict(input_image)[source]#

Predict an input image :param input_image: (numpy.ndarray)The input image data, 3-D array with layout HWC, BGR format :return: boxes

fastdeploy.vision.ocr.ClassifierPreprocessor#

class fastdeploy.vision.ocr.ClassifierPreprocessor[source]#

Create a preprocessor for ClassifierModel

disable_normalize()[source]#

This function will disable normalize in preprocessing step.

disable_permute()[source]#

This function will disable hwc2chw in preprocessing step.

run(input_ims)#

Process input image

Param

input_ims: (list of numpy.ndarray) The input images

Returns

list of FDTensor

set_normalize(mean, std, is_scale)[source]#
Set preprocess normalize parameters, please call this API to

customize the normalize parameters, otherwise it will use the default normalize parameters.

Param

mean: (list of float) mean values

Param

std: (list of float) std values

Param

is_scale: (boolean) whether to scale

use_cuda(enable_cv_cuda=False, gpu_id=-1)#

Use CUDA processors

Param

enable_cv_cuda: Ture: use CV-CUDA, False: use CUDA only

Param

gpu_id: GPU device id

fastdeploy.vision.ocr.ClassifierPostprocessor#

class fastdeploy.vision.ocr.ClassifierPostprocessor[source]#

Create a postprocessor for ClassifierModel

property cls_thresh#

Return the cls_thresh of ClassifierPostprocessor

run(runtime_results)[source]#

Postprocess the runtime results for ClassifierModel :param: runtime_results: (list of FDTensor or list of pyArray)The output FDTensor results from runtime :return: list of Result(If the runtime_results is predict by batched samples, the length of this list equals to the batch size)

fastdeploy.vision.ocr.Classifier#

class fastdeploy.vision.ocr.Classifier(model_file='', params_file='', runtime_option=None, model_format=<ModelFormat.PADDLE: 1>)[source]#

Load OCR classification model provided by PaddleOCR.

Parameters
  • model_file – (str)Path of model file, e.g ./ch_ppocr_mobile_v2.0_cls_infer/model.pdmodel.

  • params_file – (str)Path of parameter file, e.g ./ch_ppocr_mobile_v2.0_cls_infer/model.pdiparams, if the model format is ONNX, this parameter will be ignored.

  • runtime_option – (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it’s None, will use the default backend on CPU.

  • model_format – (fastdeploy.ModelForamt)Model format of the loaded model.

batch_predict(images)[source]#

Predict a batch of input image :param images: (list of numpy.ndarray) The input image list, each element is a 3-D array with layout HWC, BGR format :return: list of cls_label, list of cls_score

clone()[source]#

Clone OCR classification model object :return: a new OCR classification model object

get_profile_time()#

Get profile time of Runtime after the profile process is done.

predict(input_image)[source]#

Predict an input image :param input_image: (numpy.ndarray)The input image data, 3-D array with layout HWC, BGR format :return: cls_label, cls_score

fastdeploy.vision.ocr.RecognizerPreprocessor#

class fastdeploy.vision.ocr.RecognizerPreprocessor[source]#

Create a preprocessor for RecognizerModel

disable_normalize()[source]#

This function will disable normalize in preprocessing step.

disable_permute()[source]#

This function will disable hwc2chw in preprocessing step.

run(input_ims)#

Process input image

Param

input_ims: (list of numpy.ndarray) The input images

Returns

list of FDTensor

set_normalize(mean, std, is_scale)[source]#
Set preprocess normalize parameters, please call this API to

customize the normalize parameters, otherwise it will use the default normalize parameters.

Param

mean: (list of float) mean values

Param

std: (list of float) std values

Param

is_scale: (boolean) whether to scale

use_cuda(enable_cv_cuda=False, gpu_id=-1)#

Use CUDA processors

Param

enable_cv_cuda: Ture: use CV-CUDA, False: use CUDA only

Param

gpu_id: GPU device id

fastdeploy.vision.ocr.RecognizerPostprocessor#

class fastdeploy.vision.ocr.RecognizerPostprocessor(label_path)[source]#

Create a postprocessor for RecognizerModel :param label_path: (str)Path of label file

run(runtime_results)[source]#

Postprocess the runtime results for RecognizerModel :param: runtime_results: (list of FDTensor or list of pyArray)The output FDTensor results from runtime :return: list of Result(If the runtime_results is predict by batched samples, the length of this list equals to the batch size)

fastdeploy.vision.ocr.Recognizer#

class fastdeploy.vision.ocr.Recognizer(model_file='', params_file='', label_path='', runtime_option=None, model_format=<ModelFormat.PADDLE: 1>)[source]#

Load OCR recognition model provided by PaddleOCR

Parameters
  • model_file – (str)Path of model file, e.g ./ch_PP-OCRv3_rec_infer/model.pdmodel.

  • params_file – (str)Path of parameter file, e.g ./ch_PP-OCRv3_rec_infer/model.pdiparams, if the model format is ONNX, this parameter will be ignored.

  • label_path – (str)Path of label file used by OCR recognition model. e.g ./ppocr_keys_v1.txt

  • runtime_option – (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it’s None, will use the default backend on CPU.

  • model_format – (fastdeploy.ModelForamt)Model format of the loaded model.

batch_predict(images)[source]#

Predict a batch of input image :param images: (list of numpy.ndarray) The input image list, each element is a 3-D array with layout HWC, BGR format :return: list of rec_text, list of rec_score

clone()[source]#

Clone OCR recognition model object :return: a new OCR recognition model object

get_profile_time()#

Get profile time of Runtime after the profile process is done.

predict(input_image)[source]#

Predict an input image :param input_image: (numpy.ndarray)The input image data, 3-D array with layout HWC, BGR format :return: rec_text, rec_score

fastdeploy.vision.ocr.PPOCRv2#

class fastdeploy.vision.ocr.PPOCRv2(det_model=None, cls_model=None, rec_model=None)[source]#

Consruct a pipeline with text detector, direction classifier and text recognizer models

Parameters
  • det_model – (FastDeployModel) The detection model object created by fastdeploy.vision.ocr.DBDetector.

  • cls_model – (FastDeployModel) The classification model object created by fastdeploy.vision.ocr.Classifier.

  • rec_model – (FastDeployModel) The recognition model object created by fastdeploy.vision.ocr.Recognizer.

batch_predict(images)[source]#

Predict a batch of input image :param images: (list of numpy.ndarray) The input image list, each element is a 3-D array with layout HWC, BGR format :return: OCRBatchResult

clone()[source]#

Clone PPOCRv3 pipeline object :return: a new PPOCRv3 pipeline object

get_profile_time()#

Get profile time of Runtime after the profile process is done.

predict(input_image)[source]#

Predict an input image

Parameters

input_image – (numpy.ndarray)The input image data, 3-D array with layout HWC, BGR format

Returns

OCRResult

fastdeploy.vision.ocr.PPOCRv3#

class fastdeploy.vision.ocr.PPOCRv3(det_model=None, cls_model=None, rec_model=None)[source]#

Consruct a pipeline with text detector, direction classifier and text recognizer models

Parameters
  • det_model – (FastDeployModel) The detection model object created by fastdeploy.vision.ocr.DBDetector.

  • cls_model – (FastDeployModel) The classification model object created by fastdeploy.vision.ocr.Classifier.

  • rec_model – (FastDeployModel) The recognition model object created by fastdeploy.vision.ocr.Recognizer.

batch_predict(images)[source]#

Predict a batch of input image :param images: (list of numpy.ndarray) The input image list, each element is a 3-D array with layout HWC, BGR format :return: OCRBatchResult

clone()[source]#

Clone PPOCRv3 pipeline object :return: a new PPOCRv3 pipeline object

get_profile_time()#

Get profile time of Runtime after the profile process is done.

predict(input_image)[source]#

Predict an input image :param input_image: (numpy.ndarray)The input image data, 3-D array with layout HWC, BGR format :return: OCRResult