Skip to content

Commit

Permalink
[Model] Optimizer RVM Postprocess (PaddlePaddle#679)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Jason <[email protected]>
  • Loading branch information
3 people authored Nov 25, 2022
1 parent 124f9f8 commit 1da8c52
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 3 deletions.
Empty file modified fastdeploy/vision/common/processors/normalize_and_permute.cc
100644 → 100755
Empty file.
5 changes: 3 additions & 2 deletions fastdeploy/vision/matting/contrib/rvm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ bool RobustVideoMatting::Initialize() {

video_mode = true;

swap_rb = true;

if (!InitRuntime()) {
FDERROR << "Failed to initialize fastdeploy backend." << std::endl;
return false;
Expand All @@ -66,7 +68,7 @@ bool RobustVideoMatting::Preprocess(
// 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> 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
(*im_info)["output_shape"] = {mat->Height(), mat->Width()};
Expand Down Expand Up @@ -130,7 +132,6 @@ bool RobustVideoMatting::Postprocess(
Resize::Run(&fgr_resized, in_w, in_h, -1, -1);
}

result->Clear();
result->contain_foreground = true;
// 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};
Expand Down
3 changes: 3 additions & 0 deletions fastdeploy/vision/matting/contrib/rvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
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:
bool Initialize();
/// Preprocess an input image, and set the preprocessed results to `outputs`
Expand Down
3 changes: 2 additions & 1 deletion fastdeploy/vision/matting/contrib/rvm_pybind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ void BindRobustVideoMatting(pybind11::module& m) {
return res;
})
.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
16 changes: 16 additions & 0 deletions python/fastdeploy/vision/matting/contrib/rvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ def video_mode(self):
"""
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
def size(self, wh):
"""
Expand All @@ -79,3 +86,12 @@ def video_mode(self, value):
assert isinstance(
value, bool), "The value to set `video_mode` must be type of bool."
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 change: 1 addition & 0 deletions tests/models/test_rvm.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def test_matting_rvm_cpu():
fd.download(input_url, "resources")
model_path = "resources/rvm/rvm_mobilenetv3_fp32.onnx"
# use ORT
rc.test_option.use_ort_backend()
model = fd.vision.matting.RobustVideoMatting(
model_path, runtime_option=rc.test_option)

Expand Down

0 comments on commit 1da8c52

Please sign in to comment.