Skip to content

Commit

Permalink
[Bug Fix] Fix the PP-Matting bugs about the size computing and update…
Browse files Browse the repository at this point in the history
… PP-Matting single test (PaddlePaddle#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>
  • Loading branch information
6 people authored Oct 26, 2022
1 parent 1f6f2f6 commit da7247a
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 29 deletions.
4 changes: 2 additions & 2 deletions fastdeploy/vision/common/processors/limit_long.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fastdeploy/vision/common/processors/limit_long.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions fastdeploy/vision/common/processors/limit_short.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion fastdeploy/vision/common/processors/limit_short.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
36 changes: 19 additions & 17 deletions fastdeploy/vision/matting/ppmatting/ppmatting.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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;
Expand All @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -169,24 +169,26 @@ bool PPMatting::Postprocess(
FDERROR << "Only support post process with float32 data." << std::endl;
return false;
}
std::vector<int64_t> dim{0, 2, 3, 1};
Transpose(alpha_tensor, &alpha_tensor, dim);
alpha_tensor.Squeeze(0);
Mat mat = CreateFromTensor(alpha_tensor);

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);

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]);

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);
}

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();
Expand Down
1 change: 1 addition & 0 deletions fastdeploy/vision/matting/ppmatting/ppmatting.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions tests/eval_example/test_ppmatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit da7247a

Please sign in to comment.