paddlex.h 1.9 KB

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