[Doc] Rename PPOCRSystem to PPOCR and update comments. (#395)

* Imporve OCR Readme

* Improve OCR Readme

* Improve OCR Readme

* Improve OCR Readme

* Improve OCR Readme

* Add Initialize function to PP-OCR

* Add Initialize function to PP-OCR

* Add Initialize function to PP-OCR

* Make all the model links come from PaddleOCR

* Improve OCR readme

* Improve OCR readme

* Improve OCR readme

* Improve OCR readme

* Add Readme for vision results

* Add Readme for vision results

* Add Readme for vision results

* Add Readme for vision results

* Add Readme for vision results

* Add Readme for vision results

* Add Readme for vision results

* Add Readme for vision results

* Add Readme for vision results

* Add Readme for vision results

* Add check for label file in postprocess of Rec model

* Add check for label file in postprocess of Rec model

* Add check for label file in postprocess of Rec model

* Add check for label file in postprocess of Rec model

* Add check for label file in postprocess of Rec model

* Add check for label file in postprocess of Rec model

* Add comments to create API docs

* Improve OCR comments

* Rename OCR and add comments

* Make sure previous python example works

* Make sure previous python example works

Co-authored-by: Jason <jiangjiajun@baidu.com>
This commit is contained in:
yunyaoXYY
2022-10-19 17:21:48 +08:00
committed by GitHub
parent 85e1c647f6
commit 24317e1a14
23 changed files with 380 additions and 186 deletions

View File

@@ -24,8 +24,13 @@ class DBDetector(FastDeployModel):
params_file="",
runtime_option=None,
model_format=ModelFormat.PADDLE):
# 调用基函数进行backend_option的初始化
# 初始化后的option保存在self._runtime_option
"""Load OCR detection model provided by PaddleOCR.
:param model_file: (str)Path of model file, e.g ./ch_PP-OCRv3_det_infer/model.pdmodel.
:param 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.
:param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU.
:param model_format: (fastdeploy.ModelForamt)Model format of the loaded model.
"""
super(DBDetector, self).__init__(runtime_option)
if (len(model_file) == 0):
@@ -33,7 +38,6 @@ class DBDetector(FastDeployModel):
else:
self._model = C.vision.ocr.DBDetector(
model_file, params_file, self._runtime_option, model_format)
# 通过self.initialized判断整个模型的初始化是否成功
assert self.initialized, "DBDetector initialize failed."
# 一些跟DBDetector模型有关的属性封装
@@ -81,8 +85,8 @@ class DBDetector(FastDeployModel):
@det_db_box_thresh.setter
def det_db_box_thresh(self, value):
assert isinstance(
value,
float), "The value to set `det_db_box_thresh` must be type of float."
value, float
), "The value to set `det_db_box_thresh` must be type of float."
self._model.det_db_box_thresh = value
@det_db_unclip_ratio.setter
@@ -119,8 +123,13 @@ class Classifier(FastDeployModel):
params_file="",
runtime_option=None,
model_format=ModelFormat.PADDLE):
# 调用基函数进行backend_option的初始化
# 初始化后的option保存在self._runtime_option
"""Load OCR classification model provided by PaddleOCR.
:param model_file: (str)Path of model file, e.g ./ch_ppocr_mobile_v2.0_cls_infer/model.pdmodel.
:param 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.
:param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU.
:param model_format: (fastdeploy.ModelForamt)Model format of the loaded model.
"""
super(Classifier, self).__init__(runtime_option)
if (len(model_file) == 0):
@@ -128,7 +137,6 @@ class Classifier(FastDeployModel):
else:
self._model = C.vision.ocr.Classifier(
model_file, params_file, self._runtime_option, model_format)
# 通过self.initialized判断整个模型的初始化是否成功
assert self.initialized, "Classifier initialize failed."
@property
@@ -159,7 +167,8 @@ class Classifier(FastDeployModel):
@cls_batch_num.setter
def cls_batch_num(self, value):
assert isinstance(
value, int), "The value to set `cls_batch_num` must be type of int."
value,
int), "The value to set `cls_batch_num` must be type of int."
self._model.cls_batch_num = value
@@ -170,8 +179,14 @@ class Recognizer(FastDeployModel):
label_path="",
runtime_option=None,
model_format=ModelFormat.PADDLE):
# 调用基函数进行backend_option的初始化
# 初始化后的option保存在self._runtime_option
"""Load OCR recognition model provided by PaddleOCR
:param model_file: (str)Path of model file, e.g ./ch_PP-OCRv3_rec_infer/model.pdmodel.
:param 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.
:param label_path: (str)Path of label file used by OCR recognition model. e.g ./ppocr_keys_v1.txt
:param runtime_option: (fastdeploy.RuntimeOption)RuntimeOption for inference this model, if it's None, will use the default backend on CPU.
:param model_format: (fastdeploy.ModelForamt)Model format of the loaded model.
"""
super(Recognizer, self).__init__(runtime_option)
if (len(model_file) == 0):
@@ -180,7 +195,6 @@ class Recognizer(FastDeployModel):
self._model = C.vision.ocr.Recognizer(
model_file, params_file, label_path, self._runtime_option,
model_format)
# 通过self.initialized判断整个模型的初始化是否成功
assert self.initialized, "Recognizer initialize failed."
@property
@@ -210,33 +224,78 @@ class Recognizer(FastDeployModel):
@rec_batch_num.setter
def rec_batch_num(self, value):
assert isinstance(
value, int), "The value to set `rec_batch_num` must be type of int."
value,
int), "The value to set `rec_batch_num` must be type of int."
self._model.rec_batch_num = value
class PPOCRSystemv3(FastDeployModel):
class PPOCRv3(FastDeployModel):
def __init__(self, det_model=None, cls_model=None, rec_model=None):
"""Consruct a pipeline with text detector, direction classifier and text recognizer models
:param det_model: (FastDeployModel) The detection model object created by fastdeploy.vision.ocr.DBDetector.
:param cls_model: (FastDeployModel) The classification model object created by fastdeploy.vision.ocr.Classifier.
:param rec_model: (FastDeployModel) The recognition model object created by fastdeploy.vision.ocr.Recognizer.
"""
assert det_model is not None and rec_model is not None, "The det_model and rec_model cannot be None."
if cls_model is None:
self.system = C.vision.ocr.PPOCRSystemv3(det_model._model,
rec_model._model)
self.system = C.vision.ocr.PPOCRv3(det_model._model,
rec_model._model)
else:
self.system = C.vision.ocr.PPOCRSystemv3(
self.system = C.vision.ocr.PPOCRv3(
det_model._model, cls_model._model, rec_model._model)
def predict(self, input_image):
"""Predict an input image
:param input_image: (numpy.ndarray)The input image data, 3-D array with layout HWC, BGR format
:return: OCRResult
"""
return self.system.predict(input_image)
class PPOCRSystemv2(FastDeployModel):
class PPOCRSystemv3(PPOCRv3):
def __init__(self, det_model=None, cls_model=None, rec_model=None):
logging.warning(
"DEPRECATED: fd.vision.ocr.PPOCRSystemv3 is deprecated, "
"please use fd.vision.ocr.PPOCRv3 instead.")
super(PPOCRSystemv3, self).__init__(det_model, cls_model, rec_model)
def predict(self, input_image):
return super(PPOCRSystemv3, self).predict(input_image)
class PPOCRv2(FastDeployModel):
def __init__(self, det_model=None, cls_model=None, rec_model=None):
"""Consruct a pipeline with text detector, direction classifier and text recognizer models
:param det_model: (FastDeployModel) The detection model object created by fastdeploy.vision.ocr.DBDetector.
:param cls_model: (FastDeployModel) The classification model object created by fastdeploy.vision.ocr.Classifier.
:param rec_model: (FastDeployModel) The recognition model object created by fastdeploy.vision.ocr.Recognizer.
"""
assert det_model is not None and rec_model is not None, "The det_model and rec_model cannot be None."
if cls_model is None:
self.system = C.vision.ocr.PPOCRSystemv2(det_model._model,
rec_model._model)
self.system = C.vision.ocr.PPOCRv2(det_model._model,
rec_model._model)
else:
self.system = C.vision.ocr.PPOCRSystemv2(
self.system = C.vision.ocr.PPOCRv2(
det_model._model, cls_model._model, rec_model._model)
def predict(self, input_image):
"""Predict an input image
:param input_image: (numpy.ndarray)The input image data, 3-D array with layout HWC, BGR format
:return: OCRResult
"""
return self.system.predict(input_image)
class PPOCRSystemv2(PPOCRv2):
def __init__(self, det_model=None, cls_model=None, rec_model=None):
logging.warning(
"DEPRECATED: fd.vision.ocr.PPOCRSystemv2 is deprecated, "
"please use fd.vision.ocr.PPOCRv2 instead.")
super(PPOCRSystemv2, self).__init__(det_model, cls_model, rec_model)
def predict(self, input_image):
return super(PPOCRSystemv2, self).predict(input_image)