mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-05 16:48:03 +08:00
[Model] Optimizer RVM Postprocess (#679)
* add paddle_trt in benchmark * update benchmark in device * update benchmark * update result doc * fixed for CI * update python api_docs * update index.rst * add runtime cpp examples * deal with comments * Update infer_paddle_tensorrt.py * Add runtime quick start * deal with comments * fixed reused_input_tensors&&reused_output_tensors * fixed docs * fixed headpose typo * fixed typo * refactor yolov5 * update model infer * refactor pybind for yolov5 * rm origin yolov5 * fixed bugs * rm cuda preprocess * fixed bugs * fixed bugs * fixed bug * fixed bug * fix pybind * rm useless code * add convert_and_permute * fixed bugs * fixed im_info for bs_predict * fixed bug * add bs_predict for yolov5 * Add runtime test and batch eval * deal with comments * fixed bug * update testcase * fixed batch eval bug * fixed preprocess bug * refactor yolov7 * add yolov7 testcase * rm resize_after_load and add is_scale_up * fixed bug * set multi_label true * optimize rvm preprocess * optimizer rvm postprocess * fixed bug * deal with comments Co-authored-by: Jason <928090362@qq.com> Co-authored-by: Jason <jiangjiajun@baidu.com>
This commit is contained in:
0
fastdeploy/vision/common/processors/normalize_and_permute.cc
Normal file → Executable file
0
fastdeploy/vision/common/processors/normalize_and_permute.cc
Normal file → Executable file
@@ -47,6 +47,8 @@ bool RobustVideoMatting::Initialize() {
|
|||||||
|
|
||||||
video_mode = true;
|
video_mode = true;
|
||||||
|
|
||||||
|
swap_rb = true;
|
||||||
|
|
||||||
if (!InitRuntime()) {
|
if (!InitRuntime()) {
|
||||||
FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
|
FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
|
||||||
return false;
|
return false;
|
||||||
@@ -66,7 +68,7 @@ bool RobustVideoMatting::Preprocess(
|
|||||||
// Convert_and_permute(swap_rb=true)
|
// Convert_and_permute(swap_rb=true)
|
||||||
std::vector<float> alpha = {1.0f / 255.0f, 1.0f / 255.0f, 1.0f / 255.0f};
|
std::vector<float> alpha = {1.0f / 255.0f, 1.0f / 255.0f, 1.0f / 255.0f};
|
||||||
std::vector<float> beta = {0.0f, 0.0f, 0.0f};
|
std::vector<float> beta = {0.0f, 0.0f, 0.0f};
|
||||||
ConvertAndPermute::Run(mat, alpha, beta, true);
|
ConvertAndPermute::Run(mat, alpha, beta, swap_rb);
|
||||||
|
|
||||||
// Record output shape of preprocessed image
|
// Record output shape of preprocessed image
|
||||||
(*im_info)["output_shape"] = {mat->Height(), mat->Width()};
|
(*im_info)["output_shape"] = {mat->Height(), mat->Width()};
|
||||||
@@ -130,7 +132,6 @@ bool RobustVideoMatting::Postprocess(
|
|||||||
Resize::Run(&fgr_resized, in_w, in_h, -1, -1);
|
Resize::Run(&fgr_resized, in_w, in_h, -1, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
result->Clear();
|
|
||||||
result->contain_foreground = true;
|
result->contain_foreground = true;
|
||||||
// if contain_foreground == true, shape must set to (h, w, c)
|
// if contain_foreground == true, shape must set to (h, w, c)
|
||||||
result->shape = {static_cast<int64_t>(in_h), static_cast<int64_t>(in_w), 3};
|
result->shape = {static_cast<int64_t>(in_h), static_cast<int64_t>(in_w), 3};
|
||||||
|
@@ -58,6 +58,9 @@ class FASTDEPLOY_DECL RobustVideoMatting : public FastDeployModel {
|
|||||||
/// Whether to open the video mode, if there are some irrelevant pictures, set it to fasle, the default is true // NOLINT
|
/// Whether to open the video mode, if there are some irrelevant pictures, set it to fasle, the default is true // NOLINT
|
||||||
bool video_mode;
|
bool video_mode;
|
||||||
|
|
||||||
|
/// Whether convert to RGB, Set to false if you have converted YUV format images to RGB outside the model, dafault true // NOLINT
|
||||||
|
bool swap_rb;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool Initialize();
|
bool Initialize();
|
||||||
/// Preprocess an input image, and set the preprocessed results to `outputs`
|
/// Preprocess an input image, and set the preprocessed results to `outputs`
|
||||||
|
@@ -28,7 +28,8 @@ void BindRobustVideoMatting(pybind11::module& m) {
|
|||||||
return res;
|
return res;
|
||||||
})
|
})
|
||||||
.def_readwrite("size", &vision::matting::RobustVideoMatting::size)
|
.def_readwrite("size", &vision::matting::RobustVideoMatting::size)
|
||||||
.def_readwrite("video_mode", &vision::matting::RobustVideoMatting::video_mode);
|
.def_readwrite("video_mode", &vision::matting::RobustVideoMatting::video_mode)
|
||||||
|
.def_readwrite("swap_rb", &vision::matting::RobustVideoMatting::swap_rb);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace fastdeploy
|
} // namespace fastdeploy
|
||||||
|
@@ -59,6 +59,13 @@ class RobustVideoMatting(FastDeployModel):
|
|||||||
"""
|
"""
|
||||||
return self._model.video_mode
|
return self._model.video_mode
|
||||||
|
|
||||||
|
@property
|
||||||
|
def swap_rb(self):
|
||||||
|
"""
|
||||||
|
Whether convert to RGB, Set to false if you have converted YUV format images to RGB outside the model, dafault true
|
||||||
|
"""
|
||||||
|
return self._model.swap_rb
|
||||||
|
|
||||||
@size.setter
|
@size.setter
|
||||||
def size(self, wh):
|
def size(self, wh):
|
||||||
"""
|
"""
|
||||||
@@ -79,3 +86,12 @@ class RobustVideoMatting(FastDeployModel):
|
|||||||
assert isinstance(
|
assert isinstance(
|
||||||
value, bool), "The value to set `video_mode` must be type of bool."
|
value, bool), "The value to set `video_mode` must be type of bool."
|
||||||
self._model.video_mode = value
|
self._model.video_mode = value
|
||||||
|
|
||||||
|
@swap_rb.setter
|
||||||
|
def swap_rb(self, value):
|
||||||
|
"""
|
||||||
|
Set swap_rb property, the default is true
|
||||||
|
"""
|
||||||
|
assert isinstance(
|
||||||
|
value, bool), "The value to set `swap_rb` must be type of bool."
|
||||||
|
self._model.swap_rb = value
|
||||||
|
1
tests/models/test_rvm.py
Normal file → Executable file
1
tests/models/test_rvm.py
Normal file → Executable file
@@ -27,6 +27,7 @@ def test_matting_rvm_cpu():
|
|||||||
fd.download(input_url, "resources")
|
fd.download(input_url, "resources")
|
||||||
model_path = "resources/rvm/rvm_mobilenetv3_fp32.onnx"
|
model_path = "resources/rvm/rvm_mobilenetv3_fp32.onnx"
|
||||||
# use ORT
|
# use ORT
|
||||||
|
rc.test_option.use_ort_backend()
|
||||||
model = fd.vision.matting.RobustVideoMatting(
|
model = fd.vision.matting.RobustVideoMatting(
|
||||||
model_path, runtime_option=rc.test_option)
|
model_path, runtime_option=rc.test_option)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user