preprocessor.h 3.8 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 perception {
  21. /*! @brief Preprocessor object for Petr serials model.
  22. */
  23. class ULTRAINFER_DECL PetrPreprocessor : public ProcessorManager {
  24. public:
  25. PetrPreprocessor() = default;
  26. /** \brief Create a preprocessor instance for Petr model
  27. *
  28. * \param[in] config_file Path of configuration file for deployment, e.g
  29. * smoke/infer_cfg.yml
  30. */
  31. explicit PetrPreprocessor(const std::string &config_file);
  32. /** \brief Process the input image and prepare input tensors for runtime
  33. *
  34. * \param[in] images The input image data list, all the elements are returned
  35. * by cv::imread() \param[in] outputs The output tensors which will feed in
  36. * runtime \param[in] ims_info The shape info list, record input_shape and
  37. * output_shape \return true if the preprocess succeeded, otherwise false
  38. */
  39. bool Apply(FDMatBatch *image_batch, std::vector<FDTensor> *outputs);
  40. protected:
  41. bool BuildPreprocessPipelineFromConfig();
  42. std::vector<std::shared_ptr<Processor>> processors_;
  43. bool disable_permute_ = false;
  44. bool initialized_ = false;
  45. std::string config_file_;
  46. float scale_ = 1.0f;
  47. std::vector<float> mean_;
  48. std::vector<float> std_;
  49. std::vector<float> input_k_data_{
  50. -1.40307297e-03, 9.07780395e-06, 4.84838307e-01, -5.43047376e-02,
  51. -1.40780103e-04, 1.25770375e-05, 1.04126692e+00, 7.67668605e-01,
  52. -1.02884378e-05, -1.41007011e-03, 1.02823459e-01, -3.07415128e-01,
  53. 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.00000000e+00,
  54. -9.39000631e-04, -7.65239349e-07, 1.14073277e+00, 4.46270645e-01,
  55. 1.04998052e-03, 1.91798881e-05, 2.06218868e-01, 7.42717385e-01,
  56. 1.48074005e-05, -1.40855671e-03, 7.45946690e-02, -3.16081315e-01,
  57. 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.00000000e+00,
  58. -7.0699735e-04, 4.2389297e-07, -5.5183989e-01, -5.3276348e-01,
  59. -1.2281288e-03, 2.5626015e-05, 1.0212017e+00, 6.1102939e-01,
  60. -2.2421273e-05, -1.4170362e-03, 9.3639769e-02, -3.0863306e-01,
  61. 0.0000000e+00, 0.0000000e+00, 0.0000000e+00, 1.0000000e+00,
  62. 2.2227580e-03, 2.5312484e-06, -9.7261822e-01, 9.0684637e-02,
  63. 1.9360810e-04, 2.1347081e-05, -1.0779887e+00, -7.9227984e-01,
  64. 4.3742721e-06, -2.2310747e-03, 1.0842450e-01, -2.9406491e-01,
  65. 0.0000000e+00, 0.0000000e+00, 0.0000000e+00, 1.0000000e+00,
  66. 5.97175560e-04, -5.88774265e-06, -1.15893924e+00, -4.49921310e-01,
  67. -1.28312141e-03, 3.58297058e-07, 1.48300052e-01, 1.14334166e-01,
  68. -2.80917516e-06, -1.41527120e-03, 8.37693438e-02, -2.36765608e-01,
  69. 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 1.00000000e+00,
  70. 3.6048229e-04, 3.8333174e-06, 7.9871160e-01, 4.3321830e-01,
  71. 1.3671946e-03, 6.7484652e-06, -8.4722507e-01, 1.9411178e-01,
  72. 7.5027779e-06, -1.4139183e-03, 8.2083985e-02, -2.4505949e-01,
  73. 0.0000000e+00, 0.0000000e+00, 0.0000000e+00, 1.0000000e+00};
  74. };
  75. } // namespace perception
  76. } // namespace vision
  77. } // namespace ultra_infer