Skip to content

Commit f0dbd13

Browse files
ziqi-jinjiangjiajunrootDefTruthfelixhjh
authored
Add PPMatting Support (PaddlePaddle#163)
* 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 (PaddlePaddle#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <[email protected]> * Add PaddleDetetion/PPYOLOE model support (PaddlePaddle#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (PaddlePaddle#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 (PaddlePaddle#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 <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: DefTruth <[email protected]> Co-authored-by: huangjianhui <[email protected]> * first commit for yolor * for merge * Develop (PaddlePaddle#11) * Fix compile problem in different python version (PaddlePaddle#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <[email protected]> * Add PaddleDetetion/PPYOLOE model support (PaddlePaddle#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (PaddlePaddle#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 (PaddlePaddle#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 <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: DefTruth <[email protected]> Co-authored-by: huangjianhui <[email protected]> * Yolor (PaddlePaddle#16) * Develop (PaddlePaddle#11) (PaddlePaddle#12) * Fix compile problem in different python version (PaddlePaddle#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <[email protected]> * Add PaddleDetetion/PPYOLOE model support (PaddlePaddle#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (PaddlePaddle#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 (PaddlePaddle#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 <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: DefTruth <[email protected]> Co-authored-by: huangjianhui <[email protected]> Co-authored-by: Jason <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: DefTruth <[email protected]> Co-authored-by: huangjianhui <[email protected]> * Develop (PaddlePaddle#13) * Fix compile problem in different python version (PaddlePaddle#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <[email protected]> * Add PaddleDetetion/PPYOLOE model support (PaddlePaddle#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (PaddlePaddle#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 (PaddlePaddle#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 <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: DefTruth <[email protected]> Co-authored-by: huangjianhui <[email protected]> * documents * documents * documents * documents * documents * documents * documents * documents * documents * documents * documents * documents * Develop (PaddlePaddle#14) * Fix compile problem in different python version (PaddlePaddle#26) * fix some usage problem in linux * Fix compile problem Co-authored-by: root <[email protected]> * Add PaddleDetetion/PPYOLOE model support (PaddlePaddle#22) * add ppdet/ppyoloe * Add demo code and documents * add convert processor to vision (PaddlePaddle#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 (PaddlePaddle#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 <[email protected]> Co-authored-by: DefTruth <[email protected]> Co-authored-by: huangjianhui <[email protected]> Co-authored-by: Jason <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: DefTruth <[email protected]> Co-authored-by: huangjianhui <[email protected]> Co-authored-by: Jason <[email protected]> * add is_dynamic for YOLO series (PaddlePaddle#22) * ppmat * first commit for ppmatting * keep VisMattingAlpha with background funtion * support ppmatting and swapbackground function * modify docs error * add photos for docs * add photos for docs * add photos for docs * modify docs * modify docs * modify docs * change remove_small_connected_area function, modify docs * fix compile error Co-authored-by: Jason <[email protected]> Co-authored-by: root <[email protected]> Co-authored-by: DefTruth <[email protected]> Co-authored-by: huangjianhui <[email protected]> Co-authored-by: Jason <[email protected]>
1 parent 4d275b3 commit f0dbd13

31 files changed

+1316
-88
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ fastdeploy/ThirdPartyNotices*
1818
*.so*
1919
fastdeploy/libs/third_libs
2020
csrc/fastdeploy/core/config.h
21-
csrc/fastdeploy/pybind/main.cc
21+
csrc/fastdeploy/pybind/main.cc

csrc/fastdeploy/vision.h

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "fastdeploy/vision/faceid/contrib/partial_fc.h"
3838
#include "fastdeploy/vision/faceid/contrib/vpl.h"
3939
#include "fastdeploy/vision/matting/contrib/modnet.h"
40+
#include "fastdeploy/vision/matting/ppmatting/ppmatting.h"
4041
#include "fastdeploy/vision/ocr/ppocr/classifier.h"
4142
#include "fastdeploy/vision/ocr/ppocr/dbdetector.h"
4243
#include "fastdeploy/vision/ocr/ppocr/ppocr_system_v2.h"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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+
#include "fastdeploy/vision/common/processors/limit_short.h"
16+
17+
namespace fastdeploy {
18+
namespace vision {
19+
20+
bool LimitShort::CpuRun(Mat* mat) {
21+
cv::Mat* im = mat->GetCpuMat();
22+
int origin_w = im->cols;
23+
int origin_h = im->rows;
24+
int im_size_min = std::min(origin_w, origin_h);
25+
int target = im_size_min;
26+
if (max_short_ > 0 && im_size_min > max_short_) {
27+
target = max_short_;
28+
} else if (min_short_ > 0 && im_size_min < min_short_) {
29+
target = min_short_;
30+
}
31+
if (target != im_size_min) {
32+
double scale =
33+
static_cast<double>(target) / static_cast<double>(im_size_min);
34+
cv::resize(*im, *im, cv::Size(), scale, scale, interp_);
35+
mat->SetWidth(im->cols);
36+
mat->SetHeight(im->rows);
37+
}
38+
return true;
39+
}
40+
41+
#ifdef ENABLE_OPENCV_CUDA
42+
bool LimitShort::GpuRun(Mat* mat) {
43+
cv::cuda::GpuMat* im = mat->GetGpuMat();
44+
int origin_w = im->cols;
45+
int origin_h = im->rows;
46+
im->convertTo(*im, CV_32FC(im->channels()));
47+
int im_size_min = std::min(origin_w, origin_h);
48+
int target = im_size_min;
49+
if (max_short_ > 0 && im_size_min > max_short_) {
50+
target = max_short_;
51+
} else if (min_short_ > 0 && im_size_min < min_short_) {
52+
target = min_short_;
53+
}
54+
if (target != im_size_min) {
55+
double scale =
56+
static_cast<double>(target) / static_cast<double>(im_size_min);
57+
cv::cuda::resize(*im, *im, cv::Size(), scale, scale, interp_);
58+
mat->SetWidth(im->cols);
59+
mat->SetHeight(im->rows);
60+
}
61+
return true;
62+
}
63+
#endif
64+
65+
bool LimitShort::Run(Mat* mat, int max_short, int min_short, ProcLib lib) {
66+
auto l = LimitShort(max_short, min_short);
67+
return l(mat, lib);
68+
}
69+
} // namespace vision
70+
} // namespace fastdeploy
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
17+
#include "fastdeploy/vision/common/processors/base.h"
18+
19+
namespace fastdeploy {
20+
namespace vision {
21+
22+
class LimitShort : public Processor {
23+
public:
24+
explicit LimitShort(int max_short = -1, int min_short = -1, int interp = 1) {
25+
max_short_ = max_short;
26+
min_short_ = min_short;
27+
interp_ = interp;
28+
}
29+
bool CpuRun(Mat* mat);
30+
#ifdef ENABLE_OPENCV_CUDA
31+
bool GpuRun(Mat* mat);
32+
#endif
33+
std::string Name() { return "LimitShort"; }
34+
35+
static bool Run(Mat* mat, int max_short = -1, int min_short = -1,
36+
ProcLib lib = ProcLib::OPENCV_CPU);
37+
38+
private:
39+
int max_short_;
40+
int min_short_;
41+
int interp_;
42+
};
43+
} // namespace vision
44+
} // namespace fastdeploy
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
#include "fastdeploy/vision/common/processors/resize_to_int_mult.h"
16+
17+
namespace fastdeploy {
18+
namespace vision {
19+
20+
bool ResizeToIntMult::CpuRun(Mat* mat) {
21+
cv::Mat* im = mat->GetCpuMat();
22+
int origin_w = im->cols;
23+
int origin_h = im->rows;
24+
int rw = origin_w - origin_w % mult_int_;
25+
int rh = origin_h - origin_h % mult_int_;
26+
if (rw != origin_w || rh != origin_w) {
27+
cv::resize(*im, *im, cv::Size(rw, rh), 0, 0, interp_);
28+
mat->SetWidth(im->cols);
29+
mat->SetHeight(im->rows);
30+
}
31+
return true;
32+
}
33+
34+
#ifdef ENABLE_OPENCV_CUDA
35+
bool ResizeToIntMult::GpuRun(Mat* mat) {
36+
cv::cuda::GpuMat* im = mat->GetGpuMat();
37+
int origin_w = im->cols;
38+
int origin_h = im->rows;
39+
im->convertTo(*im, CV_32FC(im->channels()));
40+
int rw = origin_w - origin_w % mult_int_;
41+
int rh = origin_h - origin_h % mult_int_;
42+
if (rw != origin_w || rh != origin_w) {
43+
cv::cuda::resize(*im, *im, cv::Size(rw, rh), 0, 0, interp_);
44+
mat->SetWidth(im->cols);
45+
mat->SetHeight(im->rows);
46+
}
47+
return true;
48+
}
49+
#endif
50+
51+
bool ResizeToIntMult::Run(Mat* mat, int mult_int, int interp, ProcLib lib) {
52+
auto r = ResizeToIntMult(mult_int, interp);
53+
return r(mat, lib);
54+
}
55+
} // namespace vision
56+
} // namespace fastdeploy
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
17+
#include "fastdeploy/vision/common/processors/base.h"
18+
19+
namespace fastdeploy {
20+
namespace vision {
21+
22+
class ResizeToIntMult : public Processor {
23+
public:
24+
explicit ResizeToIntMult(int mult_int = 32, int interp = 1) {
25+
mult_int_ = mult_int;
26+
interp_ = interp;
27+
}
28+
bool CpuRun(Mat* mat);
29+
#ifdef ENABLE_OPENCV_CUDA
30+
bool GpuRun(Mat* mat);
31+
#endif
32+
std::string Name() { return "ResizeToIntMult"; }
33+
34+
static bool Run(Mat* mat, int mult_int = 32, int interp = 1,
35+
ProcLib lib = ProcLib::OPENCV_CPU);
36+
37+
private:
38+
int interp_;
39+
int mult_int_;
40+
};
41+
} // namespace vision
42+
} // namespace fastdeploy

csrc/fastdeploy/vision/common/processors/transform.h

+2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
#include "fastdeploy/vision/common/processors/color_space_convert.h"
2020
#include "fastdeploy/vision/common/processors/convert.h"
2121
#include "fastdeploy/vision/common/processors/hwc2chw.h"
22+
#include "fastdeploy/vision/common/processors/limit_short.h"
2223
#include "fastdeploy/vision/common/processors/normalize.h"
2324
#include "fastdeploy/vision/common/processors/pad.h"
2425
#include "fastdeploy/vision/common/processors/pad_to_size.h"
2526
#include "fastdeploy/vision/common/processors/resize.h"
2627
#include "fastdeploy/vision/common/processors/resize_by_short.h"
28+
#include "fastdeploy/vision/common/processors/resize_to_int_mult.h"
2729
#include "fastdeploy/vision/common/processors/stride_pad.h"

csrc/fastdeploy/vision/matting/matting_pybind.cc

+2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
namespace fastdeploy {
1818

1919
void BindMODNet(pybind11::module& m);
20+
void BindPPMatting(pybind11::module& m);
2021

2122
void BindMatting(pybind11::module& m) {
2223
auto matting_module =
2324
m.def_submodule("matting", "Image object matting models.");
2425
BindMODNet(matting_module);
26+
BindPPMatting(matting_module);
2527
}
2628
} // namespace fastdeploy

0 commit comments

Comments
 (0)