caddn.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved. //NOLINT
  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. #pragma once
  15. #include "ultra_infer/ultra_infer_model.h"
  16. #include "ultra_infer/vision/perception/paddle3d/caddn/postprocessor.h"
  17. #include "ultra_infer/vision/perception/paddle3d/caddn/preprocessor.h"
  18. namespace ultra_infer {
  19. namespace vision {
  20. namespace perception {
  21. /*! @brief Caddn model object used when to load a Caddn model exported by Caddn.
  22. */
  23. class ULTRAINFER_DECL Caddn : public UltraInferModel {
  24. public:
  25. /** \brief Set path of model file and the configuration of runtime.
  26. *
  27. * \param[in] model_file Path of model file, e.g Caddn/model.pdiparams
  28. * \param[in] params_file Path of parameter file, e.g Caddn/model.pdiparams,
  29. * if the model format is ONNX, this parameter will be ignored \param[in]
  30. * custom_option RuntimeOption for inference, the default will use cpu, and
  31. * choose the backend defined in "valid_cpu_backends" \param[in] model_format
  32. * Model format of the loaded model, default is Paddle format
  33. */
  34. Caddn(const std::string &model_file, const std::string &params_file,
  35. const std::string &config_file,
  36. const RuntimeOption &custom_option = RuntimeOption(),
  37. const ModelFormat &model_format = ModelFormat::PADDLE);
  38. std::string ModelName() const { return "Paddle3D/Caddn"; }
  39. /** \brief Predict the perception result for an input image
  40. *
  41. * \param[in] img The input image data, comes from cv::imread(), is a 3-D
  42. * array with layout HWC, BGR format \param[in] result The output perception
  43. * result will be written to this structure \return true if the prediction
  44. * succeeded, otherwise false
  45. */
  46. virtual bool Predict(const cv::Mat &im, std::vector<float> &input_cam_data,
  47. std::vector<float> &input_lidar_data,
  48. PerceptionResult *results);
  49. /** \brief Predict the perception results for a batch of input images
  50. *
  51. * \param[in] imgs, The input image list, each element comes from cv::imread()
  52. * \param[in] results The output perception result list
  53. * \return true if the prediction succeeded, otherwise false
  54. */
  55. virtual bool BatchPredict(const std::vector<cv::Mat> &images,
  56. std::vector<float> &input_cam_data,
  57. std::vector<float> &input_lidar_data,
  58. std::vector<PerceptionResult> *results);
  59. /// Get preprocessor reference of Caddn
  60. virtual CaddnPreprocessor &GetPreprocessor() { return preprocessor_; }
  61. /// Get postprocessor reference of Caddn
  62. virtual CaddnPostprocessor &GetPostprocessor() { return postprocessor_; }
  63. protected:
  64. bool Initialize();
  65. CaddnPreprocessor preprocessor_;
  66. CaddnPostprocessor postprocessor_;
  67. bool initialized_ = false;
  68. };
  69. } // namespace perception
  70. } // namespace vision
  71. } // namespace ultra_infer