diff --git a/fastdeploy/vision/common/processors/normalize_and_permute.cc b/fastdeploy/vision/common/processors/normalize_and_permute.cc old mode 100644 new mode 100755 diff --git a/fastdeploy/vision/matting/contrib/rvm.cc b/fastdeploy/vision/matting/contrib/rvm.cc index 7144a9018..ea37402b0 100755 --- a/fastdeploy/vision/matting/contrib/rvm.cc +++ b/fastdeploy/vision/matting/contrib/rvm.cc @@ -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; @@ -66,7 +68,7 @@ bool RobustVideoMatting::Preprocess( // Convert_and_permute(swap_rb=true) std::vector alpha = {1.0f / 255.0f, 1.0f / 255.0f, 1.0f / 255.0f}; std::vector 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()}; @@ -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(in_h), static_cast(in_w), 3}; diff --git a/fastdeploy/vision/matting/contrib/rvm.h b/fastdeploy/vision/matting/contrib/rvm.h index 58c64ac3b..3f842401b 100755 --- a/fastdeploy/vision/matting/contrib/rvm.h +++ b/fastdeploy/vision/matting/contrib/rvm.h @@ -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` diff --git a/fastdeploy/vision/matting/contrib/rvm_pybind.cc b/fastdeploy/vision/matting/contrib/rvm_pybind.cc index a45816d65..25d95f519 100755 --- a/fastdeploy/vision/matting/contrib/rvm_pybind.cc +++ b/fastdeploy/vision/matting/contrib/rvm_pybind.cc @@ -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 diff --git a/python/fastdeploy/vision/matting/contrib/rvm.py b/python/fastdeploy/vision/matting/contrib/rvm.py index 144a3823c..174719eae 100755 --- a/python/fastdeploy/vision/matting/contrib/rvm.py +++ b/python/fastdeploy/vision/matting/contrib/rvm.py @@ -59,6 +59,13 @@ class RobustVideoMatting(FastDeployModel): """ 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): """ @@ -79,3 +86,12 @@ class RobustVideoMatting(FastDeployModel): 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 diff --git a/tests/models/test_rvm.py b/tests/models/test_rvm.py old mode 100644 new mode 100755 index 4fa3083e5..c57b3f29d --- a/tests/models/test_rvm.py +++ b/tests/models/test_rvm.py @@ -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)