paddlex.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 <arm_neon.h>
  16. #include <paddle_api.h>
  17. #include <functional>
  18. #include <iostream>
  19. #include <numeric>
  20. #include <map>
  21. #include <string>
  22. #include <memory>
  23. #include "include/paddlex/config_parser.h"
  24. #include "include/paddlex/results.h"
  25. #include "include/paddlex/transforms.h"
  26. #include "yaml-cpp/yaml.h"
  27. #ifdef _WIN32
  28. #define OS_PATH_SEP "\\"
  29. #else
  30. #define OS_PATH_SEP "/"
  31. #endif
  32. namespace PaddleX {
  33. class Model {
  34. public:
  35. void Init(const std::string& model_dir,
  36. const std::string& cfg_file,
  37. int thread_num) {
  38. create_predictor(model_dir, cfg_file, thread_num);
  39. }
  40. void create_predictor(const std::string& model_dir,
  41. const std::string& cfg_file,
  42. int thread_num);
  43. bool load_config(const std::string& model_dir);
  44. bool preprocess(cv::Mat* input_im, ImageBlob* inputs);
  45. bool predict(const cv::Mat& im, ClsResult* result);
  46. bool predict(const cv::Mat& im, DetResult* result);
  47. bool predict(const cv::Mat& im, SegResult* result);
  48. std::string type;
  49. std::string name;
  50. std::map<int, std::string> labels;
  51. Transforms transforms_;
  52. ImageBlob inputs_;
  53. std::shared_ptr<paddle::lite_api::PaddlePredictor> predictor_;
  54. };
  55. } // namespace PaddleX