mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-07 09:31:35 +08:00
[CVCUDA] PP-OCR and PPDet preprocessor support use_cuda python API(#1734)
add cvcuda support in ppocr and ppdet
This commit is contained in:
@@ -17,36 +17,28 @@ from typing import Union, List
|
|||||||
import logging
|
import logging
|
||||||
from .... import FastDeployModel, ModelFormat
|
from .... import FastDeployModel, ModelFormat
|
||||||
from .... import c_lib_wrap as C
|
from .... import c_lib_wrap as C
|
||||||
|
from ...common import ProcessorManager
|
||||||
|
|
||||||
|
|
||||||
class PaddleDetPreprocessor:
|
class PaddleDetPreprocessor(ProcessorManager):
|
||||||
def __init__(self, config_file):
|
def __init__(self, config_file):
|
||||||
"""Create a preprocessor for PaddleDetection Model from configuration file
|
"""Create a preprocessor for PaddleDetection Model from configuration file
|
||||||
|
|
||||||
:param config_file: (str)Path of configuration file, e.g ppyoloe/infer_cfg.yml
|
:param config_file: (str)Path of configuration file, e.g ppyoloe/infer_cfg.yml
|
||||||
"""
|
"""
|
||||||
self._preprocessor = C.vision.detection.PaddleDetPreprocessor(
|
self._manager = C.vision.detection.PaddleDetPreprocessor(config_file)
|
||||||
config_file)
|
|
||||||
|
|
||||||
def run(self, input_ims):
|
|
||||||
"""Preprocess input images for PaddleDetection Model
|
|
||||||
|
|
||||||
:param: input_ims: (list of numpy.ndarray)The input image
|
|
||||||
:return: list of FDTensor, include image, scale_factor, im_shape
|
|
||||||
"""
|
|
||||||
return self._preprocessor.run(input_ims)
|
|
||||||
|
|
||||||
def disable_normalize(self):
|
def disable_normalize(self):
|
||||||
"""
|
"""
|
||||||
This function will disable normalize in preprocessing step.
|
This function will disable normalize in preprocessing step.
|
||||||
"""
|
"""
|
||||||
self._preprocessor.disable_normalize()
|
self._manager.disable_normalize()
|
||||||
|
|
||||||
def disable_permute(self):
|
def disable_permute(self):
|
||||||
"""
|
"""
|
||||||
This function will disable hwc2chw in preprocessing step.
|
This function will disable hwc2chw in preprocessing step.
|
||||||
"""
|
"""
|
||||||
self._preprocessor.disable_permute()
|
self._manager.disable_permute()
|
||||||
|
|
||||||
|
|
||||||
class NMSOption:
|
class NMSOption:
|
||||||
|
@@ -16,32 +16,26 @@ from __future__ import absolute_import
|
|||||||
import logging
|
import logging
|
||||||
from .... import FastDeployModel, ModelFormat
|
from .... import FastDeployModel, ModelFormat
|
||||||
from .... import c_lib_wrap as C
|
from .... import c_lib_wrap as C
|
||||||
|
from ...common import ProcessorManager
|
||||||
|
|
||||||
|
|
||||||
def sort_boxes(boxes):
|
def sort_boxes(boxes):
|
||||||
return C.vision.ocr.sort_boxes(boxes)
|
return C.vision.ocr.sort_boxes(boxes)
|
||||||
|
|
||||||
|
|
||||||
class DBDetectorPreprocessor:
|
class DBDetectorPreprocessor(ProcessorManager):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
Create a preprocessor for DBDetectorModel
|
Create a preprocessor for DBDetectorModel
|
||||||
"""
|
"""
|
||||||
self._preprocessor = C.vision.ocr.DBDetectorPreprocessor()
|
super(DBDetectorPreprocessor, self).__init__()
|
||||||
|
self._manager = 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
|
@property
|
||||||
def max_side_len(self):
|
def max_side_len(self):
|
||||||
"""Get max_side_len value.
|
"""Get max_side_len value.
|
||||||
"""
|
"""
|
||||||
return self._preprocessor.max_side_len
|
return self._manager.max_side_len
|
||||||
|
|
||||||
@max_side_len.setter
|
@max_side_len.setter
|
||||||
def max_side_len(self, value):
|
def max_side_len(self, value):
|
||||||
@@ -50,7 +44,7 @@ class DBDetectorPreprocessor:
|
|||||||
"""
|
"""
|
||||||
assert isinstance(
|
assert isinstance(
|
||||||
value, int), "The value to set `max_side_len` must be type of int."
|
value, int), "The value to set `max_side_len` must be type of int."
|
||||||
self._preprocessor.max_side_len = value
|
self._manager.max_side_len = value
|
||||||
|
|
||||||
def set_normalize(self, mean, std, is_scale):
|
def set_normalize(self, mean, std, is_scale):
|
||||||
"""Set preprocess normalize parameters, please call this API to
|
"""Set preprocess normalize parameters, please call this API to
|
||||||
@@ -60,30 +54,30 @@ class DBDetectorPreprocessor:
|
|||||||
:param: std: (list of float) std values
|
:param: std: (list of float) std values
|
||||||
:param: is_scale: (boolean) whether to scale
|
:param: is_scale: (boolean) whether to scale
|
||||||
"""
|
"""
|
||||||
self._preprocessor.set_normalize(mean, std, is_scale)
|
self._manager.set_normalize(mean, std, is_scale)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def static_shape_infer(self):
|
def static_shape_infer(self):
|
||||||
return self._preprocessor.static_shape_infer
|
return self._manager.static_shape_infer
|
||||||
|
|
||||||
@static_shape_infer.setter
|
@static_shape_infer.setter
|
||||||
def static_shape_infer(self, value):
|
def static_shape_infer(self, value):
|
||||||
assert isinstance(
|
assert isinstance(
|
||||||
value,
|
value,
|
||||||
bool), "The value to set `static_shape_infer` must be type of bool."
|
bool), "The value to set `static_shape_infer` must be type of bool."
|
||||||
self._preprocessor.static_shape_infer = value
|
self._manager.static_shape_infer = value
|
||||||
|
|
||||||
def disable_normalize(self):
|
def disable_normalize(self):
|
||||||
"""
|
"""
|
||||||
This function will disable normalize in preprocessing step.
|
This function will disable normalize in preprocessing step.
|
||||||
"""
|
"""
|
||||||
self._preprocessor.disable_normalize()
|
self._manager.disable_normalize()
|
||||||
|
|
||||||
def disable_permute(self):
|
def disable_permute(self):
|
||||||
"""
|
"""
|
||||||
This function will disable hwc2chw in preprocessing step.
|
This function will disable hwc2chw in preprocessing step.
|
||||||
"""
|
"""
|
||||||
self._preprocessor.disable_permute()
|
self._manager.disable_permute()
|
||||||
|
|
||||||
|
|
||||||
class DBDetectorPostprocessor:
|
class DBDetectorPostprocessor:
|
||||||
@@ -324,18 +318,12 @@ class DBDetector(FastDeployModel):
|
|||||||
self._model.postprocessor.use_dilation = value
|
self._model.postprocessor.use_dilation = value
|
||||||
|
|
||||||
|
|
||||||
class ClassifierPreprocessor:
|
class ClassifierPreprocessor(ProcessorManager):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Create a preprocessor for ClassifierModel
|
"""Create a preprocessor for ClassifierModel
|
||||||
"""
|
"""
|
||||||
self._preprocessor = C.vision.ocr.ClassifierPreprocessor()
|
super(ClassifierPreprocessor, self).__init__()
|
||||||
|
self._manager = C.vision.ocr.ClassifierPreprocessor()
|
||||||
def run(self, input_ims):
|
|
||||||
"""Preprocess input images for ClassifierModel
|
|
||||||
:param: input_ims: (list of numpy.ndarray)The input image
|
|
||||||
:return: list of FDTensor
|
|
||||||
"""
|
|
||||||
return self._preprocessor.run(input_ims)
|
|
||||||
|
|
||||||
def set_normalize(self, mean, std, is_scale):
|
def set_normalize(self, mean, std, is_scale):
|
||||||
"""Set preprocess normalize parameters, please call this API to
|
"""Set preprocess normalize parameters, please call this API to
|
||||||
@@ -345,30 +333,30 @@ class ClassifierPreprocessor:
|
|||||||
:param: std: (list of float) std values
|
:param: std: (list of float) std values
|
||||||
:param: is_scale: (boolean) whether to scale
|
:param: is_scale: (boolean) whether to scale
|
||||||
"""
|
"""
|
||||||
self._preprocessor.set_normalize(mean, std, is_scale)
|
self._manager.set_normalize(mean, std, is_scale)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def cls_image_shape(self):
|
def cls_image_shape(self):
|
||||||
return self._preprocessor.cls_image_shape
|
return self._manager.cls_image_shape
|
||||||
|
|
||||||
@cls_image_shape.setter
|
@cls_image_shape.setter
|
||||||
def cls_image_shape(self, value):
|
def cls_image_shape(self, value):
|
||||||
assert isinstance(
|
assert isinstance(
|
||||||
value,
|
value,
|
||||||
list), "The value to set `cls_image_shape` must be type of list."
|
list), "The value to set `cls_image_shape` must be type of list."
|
||||||
self._preprocessor.cls_image_shape = value
|
self._manager.cls_image_shape = value
|
||||||
|
|
||||||
def disable_normalize(self):
|
def disable_normalize(self):
|
||||||
"""
|
"""
|
||||||
This function will disable normalize in preprocessing step.
|
This function will disable normalize in preprocessing step.
|
||||||
"""
|
"""
|
||||||
self._preprocessor.disable_normalize()
|
self._manager.disable_normalize()
|
||||||
|
|
||||||
def disable_permute(self):
|
def disable_permute(self):
|
||||||
"""
|
"""
|
||||||
This function will disable hwc2chw in preprocessing step.
|
This function will disable hwc2chw in preprocessing step.
|
||||||
"""
|
"""
|
||||||
self._preprocessor.disable_permute()
|
self._manager.disable_permute()
|
||||||
|
|
||||||
|
|
||||||
class ClassifierPostprocessor:
|
class ClassifierPostprocessor:
|
||||||
@@ -497,29 +485,23 @@ class Classifier(FastDeployModel):
|
|||||||
self._model.postprocessor.cls_thresh = value
|
self._model.postprocessor.cls_thresh = value
|
||||||
|
|
||||||
|
|
||||||
class RecognizerPreprocessor:
|
class RecognizerPreprocessor(ProcessorManager):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Create a preprocessor for RecognizerModel
|
"""Create a preprocessor for RecognizerModel
|
||||||
"""
|
"""
|
||||||
self._preprocessor = C.vision.ocr.RecognizerPreprocessor()
|
super(RecognizerPreprocessor, self).__init__()
|
||||||
|
self._manager = C.vision.ocr.RecognizerPreprocessor()
|
||||||
def run(self, input_ims):
|
|
||||||
"""Preprocess input images for RecognizerModel
|
|
||||||
:param: input_ims: (list of numpy.ndarray)The input image
|
|
||||||
:return: list of FDTensor
|
|
||||||
"""
|
|
||||||
return self._preprocessor.run(input_ims)
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def static_shape_infer(self):
|
def static_shape_infer(self):
|
||||||
return self._preprocessor.static_shape_infer
|
return self._manager.static_shape_infer
|
||||||
|
|
||||||
@static_shape_infer.setter
|
@static_shape_infer.setter
|
||||||
def static_shape_infer(self, value):
|
def static_shape_infer(self, value):
|
||||||
assert isinstance(
|
assert isinstance(
|
||||||
value,
|
value,
|
||||||
bool), "The value to set `static_shape_infer` must be type of bool."
|
bool), "The value to set `static_shape_infer` must be type of bool."
|
||||||
self._preprocessor.static_shape_infer = value
|
self._manager.static_shape_infer = value
|
||||||
|
|
||||||
def set_normalize(self, mean, std, is_scale):
|
def set_normalize(self, mean, std, is_scale):
|
||||||
"""Set preprocess normalize parameters, please call this API to
|
"""Set preprocess normalize parameters, please call this API to
|
||||||
@@ -529,30 +511,30 @@ class RecognizerPreprocessor:
|
|||||||
:param: std: (list of float) std values
|
:param: std: (list of float) std values
|
||||||
:param: is_scale: (boolean) whether to scale
|
:param: is_scale: (boolean) whether to scale
|
||||||
"""
|
"""
|
||||||
self._preprocessor.set_normalize(mean, std, is_scale)
|
self._manager.set_normalize(mean, std, is_scale)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def rec_image_shape(self):
|
def rec_image_shape(self):
|
||||||
return self._preprocessor.rec_image_shape
|
return self._manager.rec_image_shape
|
||||||
|
|
||||||
@rec_image_shape.setter
|
@rec_image_shape.setter
|
||||||
def rec_image_shape(self, value):
|
def rec_image_shape(self, value):
|
||||||
assert isinstance(
|
assert isinstance(
|
||||||
value,
|
value,
|
||||||
list), "The value to set `rec_image_shape` must be type of list."
|
list), "The value to set `rec_image_shape` must be type of list."
|
||||||
self._preprocessor.rec_image_shape = value
|
self._manager.rec_image_shape = value
|
||||||
|
|
||||||
def disable_normalize(self):
|
def disable_normalize(self):
|
||||||
"""
|
"""
|
||||||
This function will disable normalize in preprocessing step.
|
This function will disable normalize in preprocessing step.
|
||||||
"""
|
"""
|
||||||
self._preprocessor.disable_normalize()
|
self._manager.disable_normalize()
|
||||||
|
|
||||||
def disable_permute(self):
|
def disable_permute(self):
|
||||||
"""
|
"""
|
||||||
This function will disable hwc2chw in preprocessing step.
|
This function will disable hwc2chw in preprocessing step.
|
||||||
"""
|
"""
|
||||||
self._preprocessor.disable_permute()
|
self._manager.disable_permute()
|
||||||
|
|
||||||
|
|
||||||
class RecognizerPostprocessor:
|
class RecognizerPostprocessor:
|
||||||
|
Reference in New Issue
Block a user