mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-06 00:57:33 +08:00
[Hackthon_4th 242] Support en_ppstructure_mobile_v2.0_SLANet (#1816)
* first draft * update api name * fix bug * fix bug and * fix bug in c api * fix bug in c_api --------- Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com>
This commit is contained in:
@@ -648,6 +648,107 @@ class Recognizer(FastDeployModel):
|
||||
self._model.preprocessor.rec_image_shape = value
|
||||
|
||||
|
||||
class StructureV2TablePreprocessor:
|
||||
def __init__(self):
|
||||
"""Create a preprocessor for StructureV2TableModel
|
||||
"""
|
||||
self._preprocessor = C.vision.ocr.StructureV2TablePreprocessor()
|
||||
|
||||
def run(self, input_ims):
|
||||
"""Preprocess input images for StructureV2TableModel
|
||||
:param: input_ims: (list of numpy.ndarray)The input image
|
||||
:return: list of FDTensor
|
||||
"""
|
||||
return self._preprocessor.run(input_ims)
|
||||
|
||||
|
||||
class StructureV2TablePostprocessor:
|
||||
def __init__(self):
|
||||
"""Create a postprocessor for StructureV2TableModel
|
||||
"""
|
||||
self._postprocessor = C.vision.ocr.StructureV2TablePostprocessor()
|
||||
|
||||
def run(self, runtime_results):
|
||||
"""Postprocess the runtime results for StructureV2TableModel
|
||||
: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)
|
||||
"""
|
||||
return self._postprocessor.run(runtime_results)
|
||||
|
||||
|
||||
class StructureV2Table(FastDeployModel):
|
||||
def __init__(self,
|
||||
model_file="",
|
||||
params_file="",
|
||||
table_char_dict_path="",
|
||||
runtime_option=None,
|
||||
model_format=ModelFormat.PADDLE):
|
||||
"""Load OCR StructureV2Table 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(StructureV2Table, self).__init__(runtime_option)
|
||||
|
||||
if (len(model_file) == 0):
|
||||
self._model = C.vision.ocr.StructureV2Table()
|
||||
self._runnable = False
|
||||
else:
|
||||
self._model = C.vision.ocr.StructureV2Table(
|
||||
model_file, params_file, table_char_dict_path,
|
||||
self._runtime_option, model_format)
|
||||
assert self.initialized, "Classifier initialize failed."
|
||||
self._runnable = True
|
||||
|
||||
def clone(self):
|
||||
"""Clone OCR StructureV2Table model object
|
||||
:return: a new OCR StructureV2Table model object
|
||||
"""
|
||||
|
||||
class StructureV2TableClone(StructureV2Table):
|
||||
def __init__(self, model):
|
||||
self._model = model
|
||||
|
||||
clone_model = StructureV2TableClone(self._model.clone())
|
||||
return clone_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: bbox, structure
|
||||
"""
|
||||
if self._runnable:
|
||||
return self._model.predict(input_image)
|
||||
return False
|
||||
|
||||
def batch_predict(self, images):
|
||||
"""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 bbox list, list of structure
|
||||
"""
|
||||
if self._runnable:
|
||||
return self._model.batch_predict(images)
|
||||
return False
|
||||
|
||||
@property
|
||||
def preprocessor(self):
|
||||
return self._model.preprocessor
|
||||
|
||||
@preprocessor.setter
|
||||
def preprocessor(self, value):
|
||||
self._model.preprocessor = value
|
||||
|
||||
@property
|
||||
def postprocessor(self):
|
||||
return self._model.postprocessor
|
||||
|
||||
@postprocessor.setter
|
||||
def postprocessor(self, value):
|
||||
self._model.postprocessor = value
|
||||
|
||||
|
||||
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
|
||||
@@ -800,3 +901,58 @@ class PPOCRSystemv2(PPOCRv2):
|
||||
|
||||
def predict(self, input_image):
|
||||
return super(PPOCRSystemv2, self).predict(input_image)
|
||||
|
||||
|
||||
class PPStructureV2Table(FastDeployModel):
|
||||
def __init__(self, det_model=None, rec_model=None, table_model=None):
|
||||
"""Consruct a pipeline with text detector, text recognizer and table recognizer models
|
||||
|
||||
:param det_model: (FastDeployModel) The detection model object created by fastdeploy.vision.ocr.DBDetector.
|
||||
:param rec_model: (FastDeployModel) The recognition model object created by fastdeploy.vision.ocr.Recognizer.
|
||||
:param table_model: (FastDeployModel) The table recognition model object created by fastdeploy.vision.ocr.Table.
|
||||
"""
|
||||
assert det_model is not None and rec_model is not None and table_model is not None, "The det_model, rec_model and table_model cannot be None."
|
||||
self.system_ = C.vision.ocr.PPStructureV2Table(
|
||||
det_model._model,
|
||||
rec_model._model,
|
||||
table_model._model, )
|
||||
|
||||
def clone(self):
|
||||
"""Clone PPStructureV2Table pipeline object
|
||||
:return: a new PPStructureV2Table pipeline object
|
||||
"""
|
||||
|
||||
class PPStructureV2TableClone(PPStructureV2Table):
|
||||
def __init__(self, system):
|
||||
self.system_ = system
|
||||
|
||||
clone_model = PPStructureV2TableClone(self.system_.clone())
|
||||
return clone_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)
|
||||
|
||||
def batch_predict(self, images):
|
||||
"""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
|
||||
"""
|
||||
|
||||
return self.system_.batch_predict(images)
|
||||
|
||||
|
||||
class PPStructureV2TableSystem(PPStructureV2Table):
|
||||
def __init__(self, det_model=None, rec_model=None, table_model=None):
|
||||
logging.warning(
|
||||
"DEPRECATED: fd.vision.ocr.PPStructureV2TableSystem is deprecated, "
|
||||
"please use fd.vision.ocr.PPStructureV2Table instead.")
|
||||
super(PPStructureV2TableSystem, self).__init__(det_model, rec_model,
|
||||
table_model)
|
||||
|
||||
def predict(self, input_image):
|
||||
return super(PPStructureV2TableSystem, self).predict(input_image)
|
||||
|
Reference in New Issue
Block a user