mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-06 00:57:33 +08:00
[Other]Refactor PaddleSeg with preprocessor && postprocessor && support batch (#639)
* Refactor PaddleSeg with preprocessor && postprocessor * Fix bugs * Delete redundancy code * Modify by comments * Refactor according to comments * Add batch evaluation * Add single test script * Add ppliteseg single test script && fix eval(raise) error * fix bug * Fix evaluation segmentation.py batch predict * Fix segmentation evaluation bug * Fix evaluation segmentation bugs Co-authored-by: Jason <jiangjiajun@baidu.com>
This commit is contained in:
@@ -41,35 +41,55 @@ class PaddleSegModel(FastDeployModel):
|
||||
model_format)
|
||||
assert self.initialized, "PaddleSeg model initialize failed."
|
||||
|
||||
def predict(self, input_image):
|
||||
def predict(self, image):
|
||||
"""Predict the segmentation result for an input image
|
||||
|
||||
:param im: (numpy.ndarray)The input image data, 3-D array with layout HWC, BGR format
|
||||
:return: SegmentationResult
|
||||
"""
|
||||
return self._model.predict(input_image)
|
||||
return self._model.predict(image)
|
||||
|
||||
def disable_normalize_and_permute(self):
|
||||
return self._model.disable_normalize_and_permute()
|
||||
def batch_predict(self, image_list):
|
||||
"""Predict the segmentation results for a batch of input image
|
||||
:param image_list: (list of numpy.ndarray) The input image list, each element is a 3-D array with layout HWC, BGR format
|
||||
:return list of SegmentationResult
|
||||
"""
|
||||
return self._model.batch_predict(image_list)
|
||||
|
||||
@property
|
||||
def apply_softmax(self):
|
||||
"""Atrribute of PaddleSeg model. Stating Whether applying softmax operator in the postprocess, default value is False
|
||||
|
||||
:return: value of apply_softmax(bool)
|
||||
def preprocessor(self):
|
||||
"""Get PaddleSegPreprocessor object of the loaded model
|
||||
:return PaddleSegPreprocessor
|
||||
"""
|
||||
return self._model.apply_softmax
|
||||
return self._model.preprocessor
|
||||
|
||||
@apply_softmax.setter
|
||||
def apply_softmax(self, value):
|
||||
"""Set attribute apply_softmax of PaddleSeg model.
|
||||
|
||||
:param value: (bool)The value to set apply_softmax
|
||||
@property
|
||||
def postprocessor(self):
|
||||
"""Get PaddleSegPostprocessor object of the loaded model
|
||||
:return PaddleSegPostprocessor
|
||||
"""
|
||||
assert isinstance(
|
||||
value,
|
||||
bool), "The value to set `apply_softmax` must be type of bool."
|
||||
self._model.apply_softmax = value
|
||||
return self._model.postprocessor
|
||||
|
||||
|
||||
class PaddleSegPreprocessor:
|
||||
def __init__(self, config_file):
|
||||
"""Create a preprocessor for PaddleSegModel from configuration file
|
||||
:param config_file: (str)Path of configuration file, e.g ppliteseg/deploy.yaml
|
||||
"""
|
||||
self._preprocessor = C.vision.segmentation.PaddleSegPreprocessor(
|
||||
config_file)
|
||||
|
||||
def run(self, input_ims):
|
||||
"""Preprocess input images for PaddleSegModel
|
||||
:param: input_ims: (list of numpy.ndarray)The input image
|
||||
:return: list of FDTensor
|
||||
"""
|
||||
return self._preprocessor.run(input_ims)
|
||||
|
||||
def disable_normalize_and_permute(self):
|
||||
"""To disable normalize and hwc2chw in preprocessing step.
|
||||
"""
|
||||
return self._preprocessor.disable_normalize_and_permute()
|
||||
|
||||
@property
|
||||
def is_vertical_screen(self):
|
||||
@@ -77,7 +97,7 @@ class PaddleSegModel(FastDeployModel):
|
||||
|
||||
:return: value of is_vertical_screen(bool)
|
||||
"""
|
||||
return self._model.is_vertical_screen
|
||||
return self._preprocessor.is_vertical_screen
|
||||
|
||||
@is_vertical_screen.setter
|
||||
def is_vertical_screen(self, value):
|
||||
@@ -88,4 +108,59 @@ class PaddleSegModel(FastDeployModel):
|
||||
assert isinstance(
|
||||
value,
|
||||
bool), "The value to set `is_vertical_screen` must be type of bool."
|
||||
self._model.is_vertical_screen = value
|
||||
self._preprocessor.is_vertical_screen = value
|
||||
|
||||
|
||||
class PaddleSegPostprocessor:
|
||||
def __init__(self, config_file):
|
||||
"""Create a postprocessor for PaddleSegModel from configuration file
|
||||
:param config_file: (str)Path of configuration file, e.g ppliteseg/deploy.yaml
|
||||
"""
|
||||
self._postprocessor = C.vision.segmentation.PaddleSegPostprocessor(
|
||||
config_file)
|
||||
|
||||
def run(self, runtime_results, imgs_info):
|
||||
"""Postprocess the runtime results for PaddleSegModel
|
||||
:param: runtime_results: (list of FDTensor)The output FDTensor results from runtime
|
||||
:param: imgs_info: The original input images shape info map, key is "shape_info", value is [[image_height, image_width]]
|
||||
:return: list of SegmentationResult(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, imgs_info)
|
||||
|
||||
@property
|
||||
def apply_softmax(self):
|
||||
"""Atrribute of PaddleSeg model. Stating Whether applying softmax operator in the postprocess, default value is False
|
||||
|
||||
:return: value of apply_softmax(bool)
|
||||
"""
|
||||
return self._postprocessor.apply_softmax
|
||||
|
||||
@apply_softmax.setter
|
||||
def apply_softmax(self, value):
|
||||
"""Set attribute apply_softmax of PaddleSeg model.
|
||||
|
||||
:param value: (bool)The value to set apply_softmax
|
||||
"""
|
||||
assert isinstance(
|
||||
value,
|
||||
bool), "The value to set `apply_softmax` must be type of bool."
|
||||
self._postprocessor.apply_softmax = value
|
||||
|
||||
@property
|
||||
def store_score_map(self):
|
||||
"""Atrribute of PaddleSeg model. Stating Whether storing score map in the SegmentationResult, default value is False
|
||||
|
||||
:return: value of store_score_map(bool)
|
||||
"""
|
||||
return self._postprocessor.store_score_map
|
||||
|
||||
@store_score_map.setter
|
||||
def store_score_map(self, value):
|
||||
"""Set attribute store_score_map of PaddleSeg model.
|
||||
|
||||
:param value: (bool)The value to set store_score_map
|
||||
"""
|
||||
assert isinstance(
|
||||
value,
|
||||
bool), "The value to set `store_score_map` must be type of bool."
|
||||
self._postprocessor.store_score_map = value
|
||||
|
Reference in New Issue
Block a user