-
Notifications
You must be signed in to change notification settings - Fork 690
Add PP-ModNet and PP-HumanMatting Support #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 87 commits
1684b05
71c00d9
21ab2f9
d63e862
7b3b0e2
d039e80
a34a815
eb010a8
39f64f2
d071b37
d5026ca
fb376ad
4b8737c
ce922a0
6e00b82
8c359fb
906c730
80c1223
6072757
2c6e6a4
48136f0
6feca92
ae70d4f
f591b85
f0def41
15b9160
4706e8c
dc83584
086debd
4f980b9
2e61c95
80beadf
8103772
f5f7a86
e6cec25
e25e4f2
e8a8439
a182893
3aa015f
d6b98aa
871cfc6
013921a
7a5a6d9
c996117
0aefe32
2330414
4660161
033c18e
6c94d65
85fb256
90ca4cb
f6a4ed2
3682091
ca1e110
93ba6a6
767842e
cc32733
2771a3b
a1e29ac
5ecc6fe
2780588
c00be81
9082178
4b14f56
4876b82
9cebb1f
d1e3b29
69cf0d2
2ff10e1
a673a2c
832d777
e513eac
ded2054
19db925
15be4a6
3a5b93a
f765853
c2332b0
950f948
64a13c9
09c073d
99969b6
cf248de
9d4a4c9
622fbf7
38fdf76
0c80535
8077f9b
8ccb869
337cd4e
d1cf1ad
e01fa38
3c2baaf
5af0802
26eec45
669de23
ff9a07e
d0d8a5f
b4b0755
e164e8e
2707b03
440e6fc
504e522
b37991c
690a436
71a5622
e0e521d
76c1562
1d5b56f
d267c50
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // 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. | ||
|
|
||
| #include "fastdeploy/vision/common/processors/limit_long.h" | ||
|
|
||
| namespace fastdeploy { | ||
| namespace vision { | ||
|
|
||
| bool LimitLong::CpuRun(Mat* mat) { | ||
| cv::Mat* im = mat->GetCpuMat(); | ||
| int origin_w = im->cols; | ||
| int origin_h = im->rows; | ||
| int im_size_max = std::max(origin_w, origin_h); | ||
| int target = im_size_max; | ||
| if (max_long_ > 0 && im_size_max > max_long_) { | ||
| target = max_long_; | ||
| } else if (min_long_ > 0 && im_size_max < min_long_) { | ||
| target = min_long_; | ||
| } | ||
| if (target != im_size_max) { | ||
| double scale = | ||
| static_cast<double>(target) / static_cast<double>(im_size_max); | ||
| cv::resize(*im, *im, cv::Size(), scale, scale, interp_); | ||
| mat->SetWidth(im->cols); | ||
| mat->SetHeight(im->rows); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| #ifdef ENABLE_OPENCV_CUDA | ||
| bool LimitLong::GpuRun(Mat* mat) { | ||
| cv::cuda::GpuMat* im = mat->GetGpuMat(); | ||
| int origin_w = im->cols; | ||
| int origin_h = im->rows; | ||
| im->convertTo(*im, CV_32FC(im->channels())); | ||
| int im_size_max = std::min(origin_w, origin_h); | ||
| int target = im_size_max; | ||
| if (max_long_ > 0 && im_size_max > max_long_) { | ||
| target = max_long_; | ||
| } else if (min_long_ > 0 && im_size_max < min_long_) { | ||
| target = min_long_; | ||
| } | ||
| if (target != im_size_max) { | ||
| double scale = | ||
| static_cast<double>(target) / static_cast<double>(im_size_max); | ||
| cv::cuda::resize(*im, *im, cv::Size(), scale, scale, interp_); | ||
| mat->SetWidth(im->cols); | ||
| mat->SetHeight(im->rows); | ||
| } | ||
| return true; | ||
| } | ||
| #endif | ||
|
|
||
| bool LimitLong::Run(Mat* mat, int max_long, int min_long, ProcLib lib) { | ||
| auto l = LimitLong(max_long, min_long); | ||
| return l(mat, lib); | ||
| } | ||
| } // namespace vision | ||
| } // namespace fastdeploy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // 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/vision/common/processors/base.h" | ||
|
|
||
| namespace fastdeploy { | ||
| namespace vision { | ||
|
|
||
| class LimitLong : public Processor { | ||
| public: | ||
| explicit LimitLong(int max_long = -1, int min_long = -1, int interp = 1) { | ||
| max_long_ = max_long; | ||
| min_long_ = min_long; | ||
| interp_ = interp; | ||
| } | ||
| bool CpuRun(Mat* mat); | ||
| #ifdef ENABLE_OPENCV_CUDA | ||
| bool GpuRun(Mat* mat); | ||
| #endif | ||
| std::string Name() { return "LimitLong"; } | ||
|
|
||
| static bool Run(Mat* mat, int max_long = -1, int min_long = -1, | ||
| ProcLib lib = ProcLib::OPENCV_CPU); | ||
| int GetMaxLong() { return max_long_; } | ||
|
||
|
|
||
| private: | ||
| int max_long_; | ||
| int min_long_; | ||
| int interp_; | ||
| }; | ||
| } // namespace vision | ||
| } // namespace fastdeploy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // 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. | ||
|
|
||
| #include "fastdeploy/vision/common/processors/resize_by_input_shape.h" | ||
|
|
||
| namespace fastdeploy { | ||
| namespace vision { | ||
|
|
||
| bool ResizeByInputShape::CpuRun(Mat* mat) { | ||
|
||
| if (mat->layout != Layout::HWC) { | ||
| FDERROR << "ResizeByInputShape: The format of input is not HWC." | ||
| << std::endl; | ||
| return false; | ||
| } | ||
| cv::Mat* im = mat->GetCpuMat(); | ||
| int origin_w = im->cols; | ||
| int origin_h = im->rows; | ||
| float scale_w = width_ * 1.0 / origin_w; | ||
| float scale_h = height_ * 1.0 / origin_h; | ||
| float scale = std::min(scale_w, scale_h); | ||
| cv::resize(*im, *im, cv::Size(0, 0), scale, scale, interp_); | ||
| mat->SetWidth(im->cols); | ||
| mat->SetHeight(im->rows); | ||
| return true; | ||
| } | ||
|
|
||
| #ifdef ENABLE_OPENCV_CUDA | ||
| bool ResizeByInputShape::GpuRun(Mat* mat) { | ||
| if (mat->layout != Layout::HWC) { | ||
| FDERROR << "ResizeByInputShape: The format of input is not HWC." | ||
| << std::endl; | ||
| return false; | ||
| } | ||
| cv::cuda::GpuMat* im = mat->GetGpuMat(); | ||
| int origin_w = im->cols; | ||
| int origin_h = im->rows; | ||
| float scale_w = width_ * 1.0 / origin_w; | ||
| float scale_h = height_ * 1.0 / origin_h; | ||
| float scale = std::min(scale_w, scale_h); | ||
| cv::cuda::resize(*im, *im, cv::Size(0, 0), scale, scale, interp_); | ||
| mat->SetWidth(im->cols); | ||
| mat->SetHeight(im->rows); | ||
| return true; | ||
| } | ||
| #endif | ||
|
|
||
| bool ResizeByInputShape::Run(Mat* mat, int width, int height, int interp, | ||
| ProcLib lib) { | ||
| if (mat->Height() == height && mat->Width() == width) { | ||
| return true; | ||
| } | ||
| auto r = ResizeByInputShape(width, height, interp); | ||
| return r(mat, lib); | ||
| } | ||
|
|
||
| } // namespace vision | ||
| } // namespace fastdeploy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // 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/vision/common/processors/base.h" | ||
|
|
||
| namespace fastdeploy { | ||
| namespace vision { | ||
|
|
||
| class ResizeByInputShape : public Processor { | ||
|
||
| public: | ||
| ResizeByInputShape(int width, int height, int interp = 1) { | ||
|
||
| width_ = width; | ||
| height_ = height; | ||
| interp_ = interp; | ||
| } | ||
|
|
||
| bool CpuRun(Mat* mat); | ||
| #ifdef ENABLE_OPENCV_CUDA | ||
| bool GpuRun(Mat* mat); | ||
| #endif | ||
| std::string Name() { return "ResizeByInputShape"; } | ||
|
|
||
| static bool Run(Mat* mat, int width, int height, int interp = 1, | ||
| ProcLib lib = ProcLib::OPENCV_CPU); | ||
|
|
||
| private: | ||
| int width_; | ||
| int height_; | ||
| int interp_ = 1; | ||
| }; | ||
| } // namespace vision | ||
| } // namespace fastdeploy | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的逻辑和CpuRun不一致,这里用了
std::min(), 是不是用错了?