Files
FastDeploy/fastdeploy/vision/matting/contrib/rvm.h
WJJ1995 1da8c523b0 [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>
2022-11-25 13:17:09 +08:00

96 lines
3.6 KiB
C++
Executable File

// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include "fastdeploy/fastdeploy_model.h"
#include "fastdeploy/vision/common/processors/transform.h"
#include "fastdeploy/vision/common/result.h"
namespace fastdeploy {
namespace vision {
/** \brief All image/video matting model APIs are defined inside this namespace
*
*/
namespace matting {
/*! @brief RobustVideoMatting model object used when to load a RobustVideoMatting model exported by RobustVideoMatting
*/
class FASTDEPLOY_DECL RobustVideoMatting : public FastDeployModel {
public:
/** \brief Set path of model file and configuration file, and the configuration of runtime
*
* \param[in] model_file Path of model file, e.g rvm/rvm_mobilenetv3_fp32.onnx
* \param[in] params_file Path of parameter file, if the model format is ONNX, this parameter will be ignored
* \param[in] custom_option RuntimeOption for inference, the default will use cpu, and choose the backend defined in `valid_cpu_backends`
* \param[in] model_format Model format of the loaded model, default is ONNX format
*/
RobustVideoMatting(const std::string& model_file,
const std::string& params_file = "",
const RuntimeOption& custom_option = RuntimeOption(),
const ModelFormat& model_format = ModelFormat::ONNX);
/// Get model's name
std::string ModelName() const { return "matting/RobustVideoMatting"; }
/** \brief Predict the matting result for an input image
*
* \param[in] im The input image data, comes from cv::imread()
* \param[in] result The output matting result will be writen to this structure
* \return true if the prediction successed, otherwise false
*/
bool Predict(cv::Mat* im, MattingResult* result);
/// Preprocess image size, the default is (1080, 1920)
std::vector<int> size;
/// 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`
bool Preprocess(Mat* mat, FDTensor* output,
std::map<std::string, std::array<int, 2>>* im_info);
/// Postprocess the inferenced results, and set the final result to `result`
bool Postprocess(std::vector<FDTensor>& infer_result, MattingResult* result,
const std::map<std::string, std::array<int, 2>>& im_info);
/// Init dynamic inputs datas
std::vector<std::vector<float>> dynamic_inputs_datas_ = {
{0.0f}, // r1i
{0.0f}, // r2i
{0.0f}, // r3i
{0.0f}, // r4i
{0.25f}, // downsample_ratio
};
/// Init dynamic inputs dims
std::vector<std::vector<int64_t>> dynamic_inputs_dims_ = {
{1, 1, 1, 1}, // r1i
{1, 1, 1, 1}, // r2i
{1, 1, 1, 1}, // r3i
{1, 1, 1, 1}, // r4i
{1}, // downsample_ratio
};
};
} // namespace matting
} // namespace vision
} // namespace fastdeploy