forked from PaddlePaddle/FastDeploy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CVCUDA] Vision Processor Python API and Tutorial (PaddlePaddle#1394)
* bind success * bind success fix * FDMat pybind, ResizeByShort pybind * FDMat pybind, ResizeByShort pybind, remove initialized_ * override BindProcessorManager::Run in python is available * PyProcessorManager done * vision_pybind fix * manager.py fix * add tutorials * remove Apply() bind * remove Apply() bind and fix * fix reviewed problem * fix reviewed problem * fix reviewed problem readme * fix reviewed problem readme etc * apply return outputs * nits * update readme * fix FDMatbatch * add op pybind: CenterCrop, Pad * add op overload for pass FDMatBatch --------- Co-authored-by: Wang Xinyu <[email protected]>
- Loading branch information
1 parent
cb7c8a0
commit c6480de
Showing
22 changed files
with
528 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// 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 <pybind11/operators.h> | ||
#include "fastdeploy/pybind/main.h" | ||
|
||
namespace fastdeploy { | ||
void BindProcessor(pybind11::module& m) { | ||
pybind11::class_<vision::Processor>(m, "Processor") | ||
.def("__call__", [](vision::Processor& self, | ||
vision::FDMat* mat) { return self(mat); }) | ||
.def("__call__", | ||
[](vision::Processor& self, vision::FDMatBatch* mat_batch) { | ||
return self(mat_batch); | ||
}); | ||
} | ||
|
||
} // namespace fastdeploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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/pybind/main.h" | ||
|
||
namespace fastdeploy { | ||
void BindCenterCrop(pybind11::module& m) { | ||
pybind11::class_<vision::CenterCrop, vision::Processor>( | ||
m, "CenterCrop") | ||
.def(pybind11::init<int, int>(), "Default constructor"); | ||
} | ||
|
||
} // namespace fastdeploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// 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/pybind/main.h" | ||
|
||
namespace fastdeploy { | ||
void BindFDMatBatch(pybind11::module& m) { | ||
pybind11::class_<vision::FDMatBatch>(m, "FDMatBatch") | ||
.def(pybind11::init<>(), "Default constructor") | ||
.def_readwrite("input_cache", &vision::FDMatBatch::input_cache) | ||
.def_readwrite("output_cache", &vision::FDMatBatch::output_cache) | ||
.def_readwrite("mats", &vision::FDMatBatch::mats) | ||
.def("from_mats", | ||
[](vision::FDMatBatch& self, std::vector<vision::FDMat>& _mats) { | ||
self.mats_holder = _mats; | ||
self.mats = &(self.mats_holder); | ||
}); | ||
} | ||
|
||
} // namespace fastdeploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// 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/pybind/main.h" | ||
|
||
namespace fastdeploy { | ||
void BindFDMat(pybind11::module& m) { | ||
pybind11::class_<vision::FDMat>(m, "FDMat") | ||
.def(pybind11::init<>(), "Default constructor") | ||
.def_readwrite("input_cache", &vision::FDMat::input_cache) | ||
.def_readwrite("output_cache", &vision::FDMat::output_cache) | ||
.def("from_numpy", | ||
[](vision::FDMat& self, pybind11::array& pyarray) { | ||
self = vision::WrapMat(PyArrayToCvMat(pyarray)); | ||
}) | ||
.def("print_info", &vision::FDMat::PrintInfo); | ||
} | ||
|
||
} // namespace fastdeploy |
25 changes: 25 additions & 0 deletions
25
fastdeploy/vision/common/processors/normalize_and_permute_pybind.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// 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/pybind/main.h" | ||
|
||
namespace fastdeploy { | ||
void BindNormalizeAndPermute(pybind11::module& m) { | ||
pybind11::class_<vision::NormalizeAndPermute, vision::Processor>( | ||
m, "NormalizeAndPermute") | ||
.def(pybind11::init<std::vector<float>, std::vector<float>, bool, | ||
std::vector<float>, std::vector<float>, bool>(), | ||
"Default constructor"); | ||
} | ||
|
||
} // namespace fastdeploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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/pybind/main.h" | ||
|
||
namespace fastdeploy { | ||
void BindPad(pybind11::module& m) { | ||
pybind11::class_<vision::Pad, vision::Processor>( | ||
m, "Pad") | ||
.def(pybind11::init<int, int, int, int, std::vector<float>>(), "Default constructor"); | ||
} | ||
|
||
} // namespace fastdeploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// 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/pybind/main.h" | ||
|
||
namespace fastdeploy { | ||
|
||
void BindProcessorManager(pybind11::module& m); | ||
void BindNormalizeAndPermute(pybind11::module& m); | ||
void BindProcessor(pybind11::module& m); | ||
void BindResizeByShort(pybind11::module& m); | ||
void BindCenterCrop(pybind11::module& m); | ||
void BindPad(pybind11::module& m); | ||
|
||
void BindProcessors(pybind11::module& m) { | ||
auto processors_m = | ||
m.def_submodule("processors", "Module to deploy Processors models"); | ||
BindProcessorManager(processors_m); | ||
BindProcessor(processors_m); | ||
BindNormalizeAndPermute(processors_m); | ||
BindResizeByShort(processors_m); | ||
BindCenterCrop(processors_m); | ||
BindPad(processors_m); | ||
} | ||
} // namespace fastdeploy |
23 changes: 23 additions & 0 deletions
23
fastdeploy/vision/common/processors/resize_by_short_pybind.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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/pybind/main.h" | ||
|
||
namespace fastdeploy { | ||
void BindResizeByShort(pybind11::module& m) { | ||
pybind11::class_<vision::ResizeByShort, vision::Processor>(m, "ResizeByShort") | ||
.def(pybind11::init<int, int, bool, std::vector<int>>(), | ||
"Default constructor"); | ||
} | ||
|
||
} // namespace fastdeploy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.