Skip to content

Commit 1da8c52

Browse files
[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>
1 parent 124f9f8 commit 1da8c52

File tree

6 files changed

+25
-3
lines changed

6 files changed

+25
-3
lines changed

fastdeploy/vision/common/processors/normalize_and_permute.cc

100644100755
File mode changed.

fastdeploy/vision/matting/contrib/rvm.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ bool RobustVideoMatting::Initialize() {
4747

4848
video_mode = true;
4949

50+
swap_rb = true;
51+
5052
if (!InitRuntime()) {
5153
FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
5254
return false;
@@ -66,7 +68,7 @@ bool RobustVideoMatting::Preprocess(
6668
// Convert_and_permute(swap_rb=true)
6769
std::vector<float> alpha = {1.0f / 255.0f, 1.0f / 255.0f, 1.0f / 255.0f};
6870
std::vector<float> beta = {0.0f, 0.0f, 0.0f};
69-
ConvertAndPermute::Run(mat, alpha, beta, true);
71+
ConvertAndPermute::Run(mat, alpha, beta, swap_rb);
7072

7173
// Record output shape of preprocessed image
7274
(*im_info)["output_shape"] = {mat->Height(), mat->Width()};
@@ -130,7 +132,6 @@ bool RobustVideoMatting::Postprocess(
130132
Resize::Run(&fgr_resized, in_w, in_h, -1, -1);
131133
}
132134

133-
result->Clear();
134135
result->contain_foreground = true;
135136
// if contain_foreground == true, shape must set to (h, w, c)
136137
result->shape = {static_cast<int64_t>(in_h), static_cast<int64_t>(in_w), 3};

fastdeploy/vision/matting/contrib/rvm.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class FASTDEPLOY_DECL RobustVideoMatting : public FastDeployModel {
5858
/// Whether to open the video mode, if there are some irrelevant pictures, set it to fasle, the default is true // NOLINT
5959
bool video_mode;
6060

61+
/// Whether convert to RGB, Set to false if you have converted YUV format images to RGB outside the model, dafault true // NOLINT
62+
bool swap_rb;
63+
6164
private:
6265
bool Initialize();
6366
/// Preprocess an input image, and set the preprocessed results to `outputs`

fastdeploy/vision/matting/contrib/rvm_pybind.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ void BindRobustVideoMatting(pybind11::module& m) {
2828
return res;
2929
})
3030
.def_readwrite("size", &vision::matting::RobustVideoMatting::size)
31-
.def_readwrite("video_mode", &vision::matting::RobustVideoMatting::video_mode);
31+
.def_readwrite("video_mode", &vision::matting::RobustVideoMatting::video_mode)
32+
.def_readwrite("swap_rb", &vision::matting::RobustVideoMatting::swap_rb);
3233
}
3334

3435
} // namespace fastdeploy

python/fastdeploy/vision/matting/contrib/rvm.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ def video_mode(self):
5959
"""
6060
return self._model.video_mode
6161

62+
@property
63+
def swap_rb(self):
64+
"""
65+
Whether convert to RGB, Set to false if you have converted YUV format images to RGB outside the model, dafault true
66+
"""
67+
return self._model.swap_rb
68+
6269
@size.setter
6370
def size(self, wh):
6471
"""
@@ -79,3 +86,12 @@ def video_mode(self, value):
7986
assert isinstance(
8087
value, bool), "The value to set `video_mode` must be type of bool."
8188
self._model.video_mode = value
89+
90+
@swap_rb.setter
91+
def swap_rb(self, value):
92+
"""
93+
Set swap_rb property, the default is true
94+
"""
95+
assert isinstance(
96+
value, bool), "The value to set `swap_rb` must be type of bool."
97+
self._model.swap_rb = value

tests/models/test_rvm.py

100644100755
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def test_matting_rvm_cpu():
2727
fd.download(input_url, "resources")
2828
model_path = "resources/rvm/rvm_mobilenetv3_fp32.onnx"
2929
# use ORT
30+
rc.test_option.use_ort_backend()
3031
model = fd.vision.matting.RobustVideoMatting(
3132
model_path, runtime_option=rc.test_option)
3233

0 commit comments

Comments
 (0)