paddlex.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 "yaml-cpp/yaml.h"
  19. #ifdef _WIN32
  20. #define OS_PATH_SEP "\\"
  21. #else
  22. #define OS_PATH_SEP "/"
  23. #endif
  24. #include <inference_engine.hpp>
  25. #include "include/paddlex/config_parser.h"
  26. #include "include/paddlex/results.h"
  27. #include "include/paddlex/transforms.h"
  28. using namespace InferenceEngine;
  29. namespace PaddleX {
  30. class Model {
  31. public:
  32. void Init(const std::string& model_dir,
  33. const std::string& cfg_dir,
  34. std::string device) {
  35. create_predictor(model_dir, cfg_dir, device);
  36. }
  37. void create_predictor(const std::string& model_dir,
  38. const std::string& cfg_dir,
  39. std::string device);
  40. bool load_config(const std::string& model_dir);
  41. bool preprocess(cv::Mat* input_im);
  42. bool predict(const cv::Mat& im, ClsResult* result);
  43. std::string type;
  44. std::string name;
  45. std::vector<std::string> labels;
  46. Transforms transforms_;
  47. Blob::Ptr inputs_;
  48. Blob::Ptr output_;
  49. CNNNetwork network_;
  50. ExecutableNetwork executable_network_;
  51. };
  52. } // namespce of PaddleX