mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-12-24 13:28:13 +08:00
[Bug Fix] Fix the PP-Matting bugs about the size computing and update PP-Matting single test (#435)
* first commit for yolov7 * pybind for yolov7 * CPP README.md * CPP README.md * modified yolov7.cc * README.md * python file modify * delete license in fastdeploy/ * repush the conflict part * README.md modified * README.md modified * file path modified * file path modified * file path modified * file path modified * file path modified * README modified * README modified * move some helpers to private * add examples for yolov7 * api.md modified * api.md modified * api.md modified * YOLOv7 * yolov7 release link * yolov7 release link * yolov7 release link * copyright * change some helpers to private * change variables to const and fix documents. * gitignore * Transfer some funtions to private member of class * Transfer some funtions to private member of class * Merge from develop (#9) * Fix compile problem in different python version (#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> * Add PaddleDetetion/PPYOLOE model support (#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason <jiangjiajun@baidu.com> Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> * first commit for yolor * for merge * Develop (#11) * Fix compile problem in different python version (#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> * Add PaddleDetetion/PPYOLOE model support (#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason <jiangjiajun@baidu.com> Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> * Yolor (#16) * Develop (#11) (#12) * Fix compile problem in different python version (#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> * Add PaddleDetetion/PPYOLOE model support (#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason <jiangjiajun@baidu.com> Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> Co-authored-by: Jason <jiangjiajun@baidu.com> Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> * Develop (#13) * Fix compile problem in different python version (#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> * Add PaddleDetetion/PPYOLOE model support (#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: Jason <jiangjiajun@baidu.com> Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> * documents * documents * documents * documents * documents * documents * documents * documents * documents * documents * documents * documents * Develop (#14) * Fix compile problem in different python version (#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> * Add PaddleDetetion/PPYOLOE model support (#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (#27) * update .gitignore * Added checking for cmake include dir * fixed missing trt_backend option bug when init from trt * remove un-need data layout and add pre-check for dtype * changed RGB2BRG to BGR2RGB in ppcls model * add model_zoo yolov6 c++/python demo * fixed CMakeLists.txt typos * update yolov6 cpp/README.md * add yolox c++/pybind and model_zoo demo * move some helpers to private * fixed CMakeLists.txt typos * add normalize with alpha and beta * add version notes for yolov5/yolov6/yolox * add copyright to yolov5.cc * revert normalize * fixed some bugs in yolox * fixed examples/CMakeLists.txt to avoid conflicts * add convert processor to vision * format examples/CMakeLists summary * Fix bug while the inference result is empty with YOLOv5 (#29) * Add multi-label function for yolov5 * Update README.md Update doc * Update fastdeploy_runtime.cc fix variable option.trt_max_shape wrong name * Update runtime_option.md Update resnet model dynamic shape setting name from images to x * Fix bug when inference result boxes are empty * Delete detection.py Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> Co-authored-by: Jason <jiangjiajun@baidu.com> Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> Co-authored-by: Jason <928090362@qq.com> * add is_dynamic for YOLO series (#22) * modify ppmatting backend and docs * modify ppmatting docs * fix the PPMatting size problem * fix LimitShort's log * retrigger ci * modify PPMatting docs * modify the way for dealing with LimitShort * add python comments for external models * modify resnet c++ comments * modify C++ comments for external models * modify python comments and add result class comments * fix comments compile error * modify result.h comments * fix ppmatting bugs * modify single test code * merge for yolor Co-authored-by: Jason <jiangjiajun@baidu.com> Co-authored-by: root <root@bjyz-sys-gpu-kongming3.bjyz.baidu.com> Co-authored-by: DefTruth <31974251+DefTruth@users.noreply.github.com> Co-authored-by: huangjianhui <852142024@qq.com> Co-authored-by: Jason <928090362@qq.com>
This commit is contained in:
@@ -38,8 +38,8 @@ bool LimitLong::ImplByOpenCV(Mat* mat) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LimitLong::Run(Mat* mat, int max_long, int min_long, ProcLib lib) {
|
||||
auto l = LimitLong(max_long, min_long);
|
||||
bool LimitLong::Run(Mat* mat, int max_long, int min_long, int interp, ProcLib lib) {
|
||||
auto l = LimitLong(max_long, min_long, interp);
|
||||
return l(mat, lib);
|
||||
}
|
||||
} // namespace vision
|
||||
|
||||
@@ -36,7 +36,7 @@ class LimitLong : public Processor {
|
||||
std::string Name() { return "LimitLong"; }
|
||||
|
||||
static bool Run(Mat* mat, int max_long = -1, int min_long = -1,
|
||||
ProcLib lib = ProcLib::OPENCV);
|
||||
int interp = 1, ProcLib lib = ProcLib::OPENCV);
|
||||
int GetMaxLong() const { return max_long_; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -40,8 +40,8 @@ bool LimitShort::ImplByOpenCV(Mat* mat) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LimitShort::Run(Mat* mat, int max_short, int min_short, ProcLib lib) {
|
||||
auto l = LimitShort(max_short, min_short);
|
||||
bool LimitShort::Run(Mat* mat, int max_short, int min_short, int interp, ProcLib lib) {
|
||||
auto l = LimitShort(max_short, min_short, interp);
|
||||
return l(mat, lib);
|
||||
}
|
||||
} // namespace vision
|
||||
|
||||
@@ -36,7 +36,7 @@ class LimitShort : public Processor {
|
||||
std::string Name() { return "LimitShort"; }
|
||||
|
||||
static bool Run(Mat* mat, int max_short = -1, int min_short = -1,
|
||||
ProcLib lib = ProcLib::OPENCV);
|
||||
int interp = 1, ProcLib lib = ProcLib::OPENCV);
|
||||
int GetMaxShort() const { return max_short_; }
|
||||
|
||||
private:
|
||||
|
||||
@@ -70,9 +70,9 @@ bool PPMatting::BuildPreprocessPipelineFromConfig() {
|
||||
"dimension is %zu.",
|
||||
input_shape.size());
|
||||
|
||||
bool is_fixed_input_shape = false;
|
||||
is_fixed_input_shape_ = false;
|
||||
if (input_shape[2] > 0 && input_shape[3] > 0) {
|
||||
is_fixed_input_shape = true;
|
||||
is_fixed_input_shape_ = true;
|
||||
}
|
||||
if (input_shape[2] < 0 || input_shape[3] < 0) {
|
||||
FDWARNING << "Detected dynamic input shape of your model, only Paddle "
|
||||
@@ -88,7 +88,7 @@ bool PPMatting::BuildPreprocessPipelineFromConfig() {
|
||||
if (op["type"].as<std::string>() == "LimitShort") {
|
||||
int max_short = op["max_short"] ? op["max_short"].as<int>() : -1;
|
||||
int min_short = op["min_short"] ? op["min_short"].as<int>() : -1;
|
||||
if (is_fixed_input_shape) {
|
||||
if (is_fixed_input_shape_) {
|
||||
// if the input shape is fixed, will resize by scale, and the max
|
||||
// shape will not exceed input_shape
|
||||
long_size = max_short;
|
||||
@@ -100,7 +100,7 @@ bool PPMatting::BuildPreprocessPipelineFromConfig() {
|
||||
std::make_shared<LimitShort>(max_short, min_short));
|
||||
}
|
||||
} else if (op["type"].as<std::string>() == "ResizeToIntMult") {
|
||||
if (is_fixed_input_shape) {
|
||||
if (is_fixed_input_shape_) {
|
||||
std::vector<int> max_size = {input_shape[2], input_shape[3]};
|
||||
processors_.push_back(
|
||||
std::make_shared<ResizeByShort>(long_size, 1, true, max_size));
|
||||
@@ -120,7 +120,7 @@ bool PPMatting::BuildPreprocessPipelineFromConfig() {
|
||||
processors_.push_back(std::make_shared<Normalize>(mean, std));
|
||||
} else if (op["type"].as<std::string>() == "ResizeByShort") {
|
||||
long_size = op["short_size"].as<int>();
|
||||
if (is_fixed_input_shape) {
|
||||
if (is_fixed_input_shape_) {
|
||||
std::vector<int> max_size = {input_shape[2], input_shape[3]};
|
||||
processors_.push_back(
|
||||
std::make_shared<ResizeByShort>(long_size, 1, true, max_size));
|
||||
@@ -169,24 +169,26 @@ bool PPMatting::Postprocess(
|
||||
FDERROR << "Only support post process with float32 data." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
auto iter_ipt = im_info.find("input_shape");
|
||||
auto iter_out = im_info.find("output_shape");
|
||||
|
||||
double scale_h = static_cast<double>(iter_out->second[0]) /
|
||||
static_cast<double>(iter_ipt->second[0]);
|
||||
double scale_w = static_cast<double>(iter_out->second[1]) /
|
||||
static_cast<double>(iter_ipt->second[1]);
|
||||
double actual_scale = std::min(scale_h, scale_w);
|
||||
|
||||
int size_before_pad_h = round(actual_scale * iter_ipt->second[0]);
|
||||
int size_before_pad_w = round(actual_scale * iter_ipt->second[1]);
|
||||
std::vector<int64_t> dim{0, 2, 3, 1};
|
||||
Transpose(alpha_tensor, &alpha_tensor, dim);
|
||||
alpha_tensor.Squeeze(0);
|
||||
Mat mat = CreateFromTensor(alpha_tensor);
|
||||
|
||||
Crop::Run(&mat, 0, 0, size_before_pad_w, size_before_pad_h);
|
||||
auto iter_ipt = im_info.find("input_shape");
|
||||
auto iter_out = im_info.find("output_shape");
|
||||
if (is_fixed_input_shape_){
|
||||
double scale_h = static_cast<double>(iter_out->second[0]) /
|
||||
static_cast<double>(iter_ipt->second[0]);
|
||||
double scale_w = static_cast<double>(iter_out->second[1]) /
|
||||
static_cast<double>(iter_ipt->second[1]);
|
||||
double actual_scale = std::min(scale_h, scale_w);
|
||||
|
||||
int size_before_pad_h = round(actual_scale * iter_ipt->second[0]);
|
||||
int size_before_pad_w = round(actual_scale * iter_ipt->second[1]);
|
||||
|
||||
Crop::Run(&mat, 0, 0, size_before_pad_w, size_before_pad_h);
|
||||
}
|
||||
|
||||
Resize::Run(&mat, iter_ipt->second[1], iter_ipt->second[0]);
|
||||
|
||||
result->Clear();
|
||||
|
||||
@@ -61,6 +61,7 @@ class FASTDEPLOY_DECL PPMatting : public FastDeployModel {
|
||||
|
||||
std::vector<std::shared_ptr<Processor>> processors_;
|
||||
std::string config_file_;
|
||||
bool is_fixed_input_shape_;
|
||||
};
|
||||
|
||||
} // namespace matting
|
||||
|
||||
@@ -36,9 +36,9 @@ def test_matting_ppmatting():
|
||||
# 预测图片抠图结果
|
||||
im = cv2.imread("./matting_input.jpg")
|
||||
result = model.predict(im.copy())
|
||||
pkl_url = ""
|
||||
pkl_url = "https://bj.bcebos.com/fastdeploy/tests/ppmatting_result.pkl"
|
||||
if pkl_url:
|
||||
fd.download("ppmatting_result.pkl", ".")
|
||||
fd.download(pkl_url, ".")
|
||||
with open("./ppmatting_result.pkl", "rb") as f:
|
||||
baseline = pickle.load(f)
|
||||
|
||||
@@ -66,9 +66,9 @@ def test_matting_ppmodnet():
|
||||
im = cv2.imread("./matting_input.jpg")
|
||||
result = model.predict(im.copy())
|
||||
|
||||
pkl_url = ""
|
||||
pkl_url = "https://bj.bcebos.com/fastdeploy/tests/ppmodnet_result.pkl"
|
||||
if pkl_url:
|
||||
fd.download("ppmodnet_result.pkl", ".")
|
||||
fd.download(pkl_url, ".")
|
||||
with open("./ppmodnet_result.pkl", "rb") as f:
|
||||
baseline = pickle.load(f)
|
||||
|
||||
@@ -96,9 +96,9 @@ def test_matting_pphumanmatting():
|
||||
im = cv2.imread("./matting_input.jpg")
|
||||
result = model.predict(im.copy())
|
||||
|
||||
pkl_url = ""
|
||||
pkl_url = "https://bj.bcebos.com/fastdeploy/tests/pphumanmatting_result.pkl"
|
||||
if pkl_url:
|
||||
fd.download("pphumanmatting_result.pkl", ".")
|
||||
fd.download(pkl_url, ".")
|
||||
|
||||
with open("./pphumanmatting_result.pkl", "rb") as f:
|
||||
baseline = pickle.load(f)
|
||||
|
||||
Reference in New Issue
Block a user