preprocessor.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #pragma once
  15. #include "ultra_infer/vision/common/processors/manager.h"
  16. #include "ultra_infer/vision/common/processors/transform.h"
  17. #include "ultra_infer/vision/common/result.h"
  18. namespace ultra_infer {
  19. namespace vision {
  20. namespace segmentation {
  21. /*! @brief Preprocessor object for PaddleSeg serials model.
  22. */
  23. class ULTRAINFER_DECL PaddleSegPreprocessor : public ProcessorManager {
  24. public:
  25. /** \brief Create a preprocessor instance for PaddleSeg serials model
  26. *
  27. * \param[in] config_file Path of configuration file for deployment, e.g
  28. * ppliteseg/deploy.yaml
  29. */
  30. explicit PaddleSegPreprocessor(const std::string &config_file);
  31. /** \brief Implement the virtual function of ProcessorManager, Apply() is the
  32. * body of Run(). Apply() contains the main logic of preprocessing, Run() is
  33. * called by users to execute preprocessing
  34. *
  35. * \param[in] image_batch The input image batch
  36. * \param[in] outputs The output tensors which will feed in runtime
  37. * \return true if the preprocess succeeded, otherwise false
  38. */
  39. virtual bool Apply(FDMatBatch *image_batch, std::vector<FDTensor> *outputs);
  40. /// Get is_vertical_screen property of PP-HumanSeg model, default is false
  41. bool GetIsVerticalScreen() const { return is_vertical_screen_; }
  42. /// Set is_vertical_screen value, bool type required
  43. void SetIsVerticalScreen(bool value) { is_vertical_screen_ = value; }
  44. /// This function will disable normalize in preprocessing step.
  45. void DisableNormalize();
  46. /// This function will disable hwc2chw in preprocessing step.
  47. void DisablePermute();
  48. /// This function will set imgs_info_ in PaddleSegPreprocessor
  49. void SetImgsInfo(
  50. std::map<std::string, std::vector<std::array<int, 2>>> *imgs_info) {
  51. imgs_info_ = imgs_info;
  52. }
  53. /// This function will get imgs_info_ in PaddleSegPreprocessor
  54. std::map<std::string, std::vector<std::array<int, 2>>> *GetImgsInfo() {
  55. return imgs_info_;
  56. }
  57. private:
  58. virtual bool BuildPreprocessPipelineFromConfig();
  59. std::vector<std::shared_ptr<Processor>> processors_;
  60. std::string config_file_;
  61. /** \brief For PP-HumanSeg model, set true if the input image is vertical
  62. * image(height > width), default value is false
  63. */
  64. bool is_vertical_screen_ = false;
  65. // for recording the switch of hwc2chw
  66. bool disable_permute_ = false;
  67. // for recording the switch of normalize
  68. bool disable_normalize_ = false;
  69. bool is_contain_resize_op_ = false;
  70. bool initialized_ = false;
  71. std::map<std::string, std::vector<std::array<int, 2>>> *imgs_info_;
  72. std::shared_ptr<Resize> pre_resize_op_ = std::make_shared<Resize>(0, 0);
  73. };
  74. } // namespace segmentation
  75. } // namespace vision
  76. } // namespace ultra_infer