Skip to content

Commit

Permalink
Improve PPOCR API docs
Browse files Browse the repository at this point in the history
  • Loading branch information
yunyaoXYY committed Feb 23, 2023
1 parent cbe7066 commit 5a2f286
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 4 deletions.
50 changes: 50 additions & 0 deletions docs/api_docs/python/ocr.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# OCR(文字识别)

## fastdeploy.vision.ocr.DBDetectorPreprocessor

```{eval-rst}
.. autoclass:: fastdeploy.vision.ocr.DBDetectorPreprocessor
:members:
:inherited-members:
```

## fastdeploy.vision.ocr.DBDetectorPostprocessor

```{eval-rst}
.. autoclass:: fastdeploy.vision.ocr.DBDetectorPostprocessor
:members:
:inherited-members:
```


## fastdeploy.vision.ocr.DBDetector

```{eval-rst}
Expand All @@ -8,6 +25,22 @@
:inherited-members:
```

## fastdeploy.vision.ocr.ClassifierPreprocessor

```{eval-rst}
.. autoclass:: fastdeploy.vision.ocr.ClassifierPreprocessor
:members:
:inherited-members:
```

## fastdeploy.vision.ocr.ClassifierPostprocessor

```{eval-rst}
.. autoclass:: fastdeploy.vision.ocr.ClassifierPostprocessor
:members:
:inherited-members:
```

## fastdeploy.vision.ocr.Classifier

```{eval-rst}
Expand All @@ -16,6 +49,23 @@
:inherited-members:
```


## fastdeploy.vision.ocr.RecognizerPreprocessor

```{eval-rst}
.. autoclass:: fastdeploy.vision.ocr.RecognizerPreprocessor
:members:
:inherited-members:
```

## fastdeploy.vision.ocr.ClassifierPostprocessor

```{eval-rst}
.. autoclass:: fastdeploy.vision.ocr.RecognizerPostprocessor
:members:
:inherited-members:
```

## fastdeploy.vision.ocr.Recognizer

```{eval-rst}
Expand Down
60 changes: 56 additions & 4 deletions python/fastdeploy/vision/ocr/ppocr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,32 @@ def sort_boxes(boxes):

class DBDetectorPreprocessor:
def __init__(self):
"""Create a preprocessor for DBDetectorModel
"""
Create a preprocessor for DBDetectorModel
"""
self._preprocessor = C.vision.ocr.DBDetectorPreprocessor()

def run(self, input_ims):
"""Preprocess input images for DBDetectorModel
:param: input_ims: (list of numpy.ndarray) The input image
:return: pair(list of FDTensor, list of std::array<int, 4>)
"""
return self._preprocessor.run(input_ims)

@property
def max_side_len(self):
"""
Return the max_side_len of DBDetectorPreprocessor
"""
return self._preprocessor.max_side_len

@max_side_len.setter
def max_side_len(self, value):
"""Set the max_side_len for DBDetectorPreprocessor
:param: value : the max_side_len value
"""
assert isinstance(
value, int), "The value to set `max_side_len` must be type of int."
self._preprocessor.max_side_len = value
Expand Down Expand Up @@ -78,12 +87,14 @@ def mean(self, value):

class DBDetectorPostprocessor:
def __init__(self):
"""Create a postprocessor for DBDetectorModel
"""
Create a postprocessor for DBDetectorModel
"""
self._postprocessor = C.vision.ocr.DBDetectorPostprocessor()

def run(self, runtime_results, batch_det_img_info):
"""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
:return: list of Result(If the runtime_results is predict by batched samples, the length of this list equals to the batch size)
Expand All @@ -92,54 +103,89 @@ def run(self, runtime_results, batch_det_img_info):

@property
def det_db_thresh(self):
"""
Return the det_db_thresh of DBDetectorPostprocessor
"""
return self._postprocessor.det_db_thresh

@det_db_thresh.setter
def det_db_thresh(self, value):
"""Set the det_db_thresh for DBDetectorPostprocessor
:param: value : the det_db_thresh value
"""
assert isinstance(
value,
float), "The value to set `det_db_thresh` must be type of float."
self._postprocessor.det_db_thresh = value

@property
def det_db_box_thresh(self):
"""
Return the det_db_box_thresh of DBDetectorPostprocessor
"""
return self._postprocessor.det_db_box_thresh

@det_db_box_thresh.setter
def det_db_box_thresh(self, value):
"""Set the det_db_box_thresh for DBDetectorPostprocessor
:param: value : the det_db_box_thresh value
"""
assert isinstance(
value, float
), "The value to set `det_db_box_thresh` must be type of float."
self._postprocessor.det_db_box_thresh = value

@property
def det_db_unclip_ratio(self):
"""
Return the det_db_unclip_ratio of DBDetectorPostprocessor
"""
return self._postprocessor.det_db_unclip_ratio

@det_db_unclip_ratio.setter
def det_db_unclip_ratio(self, value):
"""Set the det_db_unclip_ratio for DBDetectorPostprocessor
:param: value : the det_db_unclip_ratio value
"""
assert isinstance(
value, float
), "The value to set `det_db_unclip_ratio` must be type of float."
self._postprocessor.det_db_unclip_ratio = value

@property
def det_db_score_mode(self):
"""
Return the det_db_score_mode of DBDetectorPostprocessor
"""
return self._postprocessor.det_db_score_mode

@det_db_score_mode.setter
def det_db_score_mode(self, value):
"""Set the det_db_score_mode for DBDetectorPostprocessor
:param: value : the det_db_score_mode value
"""
assert isinstance(
value,
str), "The value to set `det_db_score_mode` must be type of str."
self._postprocessor.det_db_score_mode = value

@property
def use_dilation(self):
"""
Return the use_dilation of DBDetectorPostprocessor
"""
return self._postprocessor.use_dilation

@use_dilation.setter
def use_dilation(self, value):
"""Set the use_dilation for DBDetectorPostprocessor
:param: value : the use_dilation value
"""
assert isinstance(
value,
bool), "The value to set `use_dilation` must be type of bool."
Expand Down Expand Up @@ -172,8 +218,10 @@ def __init__(self,

def clone(self):
"""Clone OCR detection model object
:return: a new OCR detection model object
"""

class DBDetectorClone(DBDetector):
def __init__(self, model):
self._model = model
Expand Down Expand Up @@ -421,6 +469,7 @@ def clone(self):
"""Clone OCR classification model object
:return: a new OCR classification model object
"""

class ClassifierClone(Classifier):
def __init__(self, model):
self._model = model
Expand Down Expand Up @@ -629,6 +678,7 @@ def clone(self):
"""Clone OCR recognition model object
:return: a new OCR recognition model object
"""

class RecognizerClone(Recognizer):
def __init__(self, model):
self._model = model
Expand Down Expand Up @@ -734,7 +784,7 @@ def __init__(self, det_model=None, cls_model=None, rec_model=None):
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.PPOCRv3(det_model._model,
rec_model._model)
rec_model._model)
else:
self.system_ = C.vision.ocr.PPOCRv3(
det_model._model, cls_model._model, rec_model._model)
Expand All @@ -743,6 +793,7 @@ def clone(self):
"""Clone PPOCRv3 pipeline object
:return: a new PPOCRv3 pipeline object
"""

class PPOCRv3Clone(PPOCRv3):
def __init__(self, system):
self.system_ = system
Expand Down Expand Up @@ -809,7 +860,7 @@ def __init__(self, det_model=None, cls_model=None, rec_model=None):
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.PPOCRv2(det_model._model,
rec_model._model)
rec_model._model)
else:
self.system_ = C.vision.ocr.PPOCRv2(
det_model._model, cls_model._model, rec_model._model)
Expand All @@ -818,6 +869,7 @@ def clone(self):
"""Clone PPOCRv3 pipeline object
:return: a new PPOCRv3 pipeline object
"""

class PPOCRv2Clone(PPOCRv2):
def __init__(self, system):
self.system_ = system
Expand Down

0 comments on commit 5a2f286

Please sign in to comment.