base_preprocess.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Copyright (c) 2020 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 <iostream>
  16. #include <memory>
  17. #include <string>
  18. #include <vector>
  19. #include "yaml-cpp/yaml.h"
  20. #include "model_deploy/common/include/output_struct.h"
  21. #include "model_deploy/common/include/transforms.h"
  22. namespace PaddleDeploy {
  23. class BasePreprocess {
  24. public:
  25. virtual bool Init(const YAML::Node& yaml_config) {
  26. if (!BuildTransform(yaml_config))
  27. return false;
  28. return true;
  29. }
  30. bool PreprocessImages(const std::vector<ShapeInfo>& shape_infos,
  31. std::vector<cv::Mat>* imgs,
  32. int thread_num = 1);
  33. bool ShapeInfer(const std::vector<cv::Mat>& imgs,
  34. std::vector<ShapeInfo>* shape_infos,
  35. int thread_num = 1);
  36. virtual bool Run(std::vector<cv::Mat>* imgs,
  37. std::vector<DataBlob>* inputs,
  38. std::vector<ShapeInfo>* shape_info,
  39. int thread_num = 1) = 0;
  40. virtual std::string GetModelName() { return model_name_; }
  41. protected:
  42. bool BuildTransform(const YAML::Node& yaml_config);
  43. std::vector<std::shared_ptr<Transform>> transforms_;
  44. private:
  45. std::shared_ptr<Transform> CreateTransform(const std::string& name);
  46. Padding batch_padding_;
  47. Permute permute_;
  48. std::string model_name_;
  49. };
  50. } // namespace PaddleDeploy