ppsr_pybind.cc 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #include "ultra_infer/pybind/main.h"
  15. namespace ultra_infer {
  16. void BindPPSR(pybind11::module &m) {
  17. pybind11::class_<vision::sr::PPMSVSR, UltraInferModel>(m, "PPMSVSR")
  18. .def(pybind11::init<std::string, std::string, RuntimeOption,
  19. ModelFormat>())
  20. .def("predict",
  21. [](vision::sr::PPMSVSR &self, std::vector<pybind11::array> &datas) {
  22. std::vector<cv::Mat> inputs;
  23. for (auto &data : datas) {
  24. auto mat = PyArrayToCvMat(data);
  25. inputs.push_back(mat);
  26. }
  27. std::vector<cv::Mat> res;
  28. std::vector<pybind11::array> res_pyarray;
  29. self.Predict(inputs, res);
  30. for (auto &img : res) {
  31. auto ret = pybind11::array_t<unsigned char>(
  32. {img.rows, img.cols, img.channels()}, img.data);
  33. res_pyarray.push_back(ret);
  34. }
  35. return res_pyarray;
  36. });
  37. pybind11::class_<vision::sr::EDVR, UltraInferModel>(m, "EDVR")
  38. .def(pybind11::init<std::string, std::string, RuntimeOption,
  39. ModelFormat>())
  40. .def("predict",
  41. [](vision::sr::EDVR &self, std::vector<pybind11::array> &datas) {
  42. std::vector<cv::Mat> inputs;
  43. for (auto &data : datas) {
  44. auto mat = PyArrayToCvMat(data);
  45. inputs.push_back(mat);
  46. }
  47. std::vector<cv::Mat> res;
  48. std::vector<pybind11::array> res_pyarray;
  49. self.Predict(inputs, res);
  50. for (auto &img : res) {
  51. auto ret = pybind11::array_t<unsigned char>(
  52. {img.rows, img.cols, img.channels()}, img.data);
  53. res_pyarray.push_back(ret);
  54. }
  55. return res_pyarray;
  56. });
  57. pybind11::class_<vision::sr::BasicVSR, UltraInferModel>(m, "BasicVSR")
  58. .def(pybind11::init<std::string, std::string, RuntimeOption,
  59. ModelFormat>())
  60. .def("predict",
  61. [](vision::sr::BasicVSR &self, std::vector<pybind11::array> &datas) {
  62. std::vector<cv::Mat> inputs;
  63. for (auto &data : datas) {
  64. auto mat = PyArrayToCvMat(data);
  65. inputs.push_back(mat);
  66. }
  67. std::vector<cv::Mat> res;
  68. std::vector<pybind11::array> res_pyarray;
  69. self.Predict(inputs, res);
  70. for (auto &img : res) {
  71. auto ret = pybind11::array_t<unsigned char>(
  72. {img.rows, img.cols, img.channels()}, img.data);
  73. res_pyarray.push_back(ret);
  74. }
  75. return res_pyarray;
  76. });
  77. }
  78. } // namespace ultra_infer