centerpoint_pybind.cc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 BindCenterpoint(pybind11::module &m) {
  17. pybind11::class_<vision::perception::CenterpointPreprocessor,
  18. vision::ProcessorManager>(m, "CenterpointPreprocessor")
  19. .def(pybind11::init<std::string>())
  20. .def("run", [](vision::perception::CenterpointPreprocessor &self,
  21. std::vector<std::string> points_dir,
  22. const int64_t num_point_dim, const int with_timelag) {
  23. std::vector<FDTensor> outputs;
  24. if (!self.Run(points_dir, num_point_dim, with_timelag, outputs)) {
  25. throw std::runtime_error("Failed to preprocess the input data in "
  26. "CenterpointPreprocessor.");
  27. }
  28. return outputs;
  29. });
  30. pybind11::class_<vision::perception::Centerpoint, UltraInferModel>(
  31. m, "Centerpoint")
  32. .def(pybind11::init<std::string, std::string, std::string, RuntimeOption,
  33. ModelFormat>())
  34. .def("predict",
  35. [](vision::perception::Centerpoint &self, std::string point_dir) {
  36. vision::PerceptionResult result;
  37. self.Predict(point_dir, &result);
  38. return result;
  39. })
  40. .def("batch_predict",
  41. [](vision::perception::Centerpoint &self,
  42. std::vector<std::string> &points_dir) {
  43. std::vector<vision::PerceptionResult> results;
  44. self.BatchPredict(points_dir, &results);
  45. return results;
  46. })
  47. .def_property_readonly("preprocessor",
  48. &vision::perception::Centerpoint::GetPreprocessor)
  49. .def_property_readonly(
  50. "postprocessor", &vision::perception::Centerpoint::GetPostprocessor);
  51. }
  52. } // namespace ultra_infer