FastDeploy  latest
Fast & Easy to Deploy!
rvm.h
1 // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 #include "fastdeploy/fastdeploy_model.h"
17 #include "fastdeploy/vision/common/processors/transform.h"
18 #include "fastdeploy/vision/common/result.h"
19 
20 namespace fastdeploy {
21 
22 namespace vision {
26 namespace matting {
27 
30 class FASTDEPLOY_DECL RobustVideoMatting : public FastDeployModel {
31  public:
39  RobustVideoMatting(const std::string& model_file,
40  const std::string& params_file = "",
41  const RuntimeOption& custom_option = RuntimeOption(),
42  const ModelFormat& model_format = ModelFormat::ONNX);
43 
45  std::string ModelName() const { return "matting/RobustVideoMatting"; }
46 
53  bool Predict(cv::Mat* im, MattingResult* result);
54 
56  std::vector<int> size;
57 
59  bool video_mode;
60 
62  bool swap_rb;
63 
64  private:
65  bool Initialize();
67  bool Preprocess(Mat* mat, FDTensor* output,
68  std::map<std::string, std::array<int, 2>>* im_info);
69 
71  bool Postprocess(std::vector<FDTensor>& infer_result, MattingResult* result,
72  const std::map<std::string, std::array<int, 2>>& im_info);
73 
75  std::vector<std::vector<float>> dynamic_inputs_datas_ = {
76  {0.0f}, // r1i
77  {0.0f}, // r2i
78  {0.0f}, // r3i
79  {0.0f}, // r4i
80  {0.25f}, // downsample_ratio
81  };
82 
84  std::vector<std::vector<int64_t>> dynamic_inputs_dims_ = {
85  {1, 1, 1, 1}, // r1i
86  {1, 1, 1, 1}, // r2i
87  {1, 1, 1, 1}, // r3i
88  {1, 1, 1, 1}, // r4i
89  {1}, // downsample_ratio
90  };
91 };
92 
93 } // namespace matting
94 } // namespace vision
95 } // namespace fastdeploy
Option object used when create a new Runtime object.
Definition: runtime_option.h:40
bool video_mode
Whether to open the video mode, if there are some irrelevant pictures, set it to fasle, the default is true // NOLINT.
Definition: rvm.h:59
Base model object for all the vision models.
Definition: fastdeploy_model.h:21
ModelFormat
Definition: enum_variables.h:67
FDTensor object used to represend data matrix.
Definition: fd_tensor.h:31
RobustVideoMatting model object used when to load a RobustVideoMatting model exported by RobustVideoM...
Definition: rvm.h:30
std::string ModelName() const
Get model&#39;s name.
Definition: rvm.h:45
Matting result structure for all the Matting models.
Definition: result.h:331
FDMat is a structure for replace cv::Mat.
Definition: mat.h:34
bool swap_rb
Whether convert to RGB, Set to false if you have converted YUV format images to RGB outside the model...
Definition: rvm.h:62
Model with ONNX format.
Definition: enum_variables.h:70
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16
std::vector< int > size
Preprocess image size, the default is (1080, 1920)
Definition: rvm.h:56