Skip to content

Commit 08a2a28

Browse files
[Model] Optimize RVM Preprocess (PaddlePaddle#658)
* 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 Co-authored-by: Jason <[email protected]> Co-authored-by: Jason <[email protected]>
1 parent 38e9645 commit 08a2a28

File tree

1 file changed

+4
-12
lines changed
  • fastdeploy/vision/matting/contrib

1 file changed

+4
-12
lines changed

fastdeploy/vision/matting/contrib/rvm.cc

+4-12
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,16 @@ bool RobustVideoMatting::Preprocess(
6363
if (resize_h != mat->Height() || resize_w != mat->Width()) {
6464
Resize::Run(mat, resize_w, resize_h);
6565
}
66-
BGR2RGB::Run(mat);
67-
68-
// Normalize
66+
// Convert_and_permute(swap_rb=true)
6967
std::vector<float> alpha = {1.0f / 255.0f, 1.0f / 255.0f, 1.0f / 255.0f};
7068
std::vector<float> beta = {0.0f, 0.0f, 0.0f};
71-
Convert::Run(mat, alpha, beta);
69+
ConvertAndPermute::Run(mat, alpha, beta, true);
70+
7271
// Record output shape of preprocessed image
7372
(*im_info)["output_shape"] = {mat->Height(), mat->Width()};
7473

75-
HWC2CHW::Run(mat);
76-
Cast::Run(mat, "float");
77-
7874
mat->ShareWithTensor(output);
79-
output->shape.insert(output->shape.begin(), 1); // reshape to n, h, w, c
75+
output->ExpandDim(0); // reshape to n, h, w, c
8076
return true;
8177
}
8278

@@ -120,8 +116,6 @@ bool RobustVideoMatting::Postprocess(
120116

121117
// for alpha
122118
float* alpha_ptr = static_cast<float*>(alpha.Data());
123-
// cv::Mat alpha_zero_copy_ref(out_h, out_w, CV_32FC1, alpha_ptr);
124-
// Mat alpha_resized(alpha_zero_copy_ref); // ref-only, zero copy.
125119
Mat alpha_resized = Mat::Create(out_h, out_w, 1, FDDataType::FP32,
126120
alpha_ptr); // ref-only, zero copy.
127121
if ((out_h != in_h) || (out_w != in_w)) {
@@ -130,8 +124,6 @@ bool RobustVideoMatting::Postprocess(
130124

131125
// for foreground
132126
float* fgr_ptr = static_cast<float*>(fgr.Data());
133-
// cv::Mat fgr_zero_copy_ref(out_h, out_w, CV_32FC1, fgr_ptr);
134-
// Mat fgr_resized(fgr_zero_copy_ref); // ref-only, zero copy.
135127
Mat fgr_resized = Mat::Create(out_h, out_w, 1, FDDataType::FP32,
136128
fgr_ptr); // ref-only, zero copy.
137129
if ((out_h != in_h) || (out_w != in_w)) {

0 commit comments

Comments
 (0)