x_preprocess.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (c) 2021 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. #include "model_deploy/paddlex/include/x_preprocess.h"
  15. namespace PaddleDeploy {
  16. bool XPreprocess::Init(const YAML::Node& yaml_config) {
  17. model_type_ = yaml_config["model_type"].as<std::string>();
  18. model_name_ = yaml_config["model_name"].as<std::string>();
  19. if (model_type_ == "segmenter") {
  20. return seg_preprocess.Init(yaml_config);
  21. } else if (model_type_ == "classifier") {
  22. return clas_preprocess.Init(yaml_config);
  23. } else if (model_type_ == "detector") {
  24. return det_preprocess.Init(yaml_config);
  25. } else {
  26. std::cerr << "[ERROR] Unexpected model_type: '"
  27. << model_type_ << "' in preprocess Init"
  28. << std::endl;
  29. return false;
  30. }
  31. return true;
  32. }
  33. bool XPreprocess::Run(std::vector<cv::Mat>* imgs,
  34. std::vector<DataBlob>* inputs,
  35. std::vector<ShapeInfo>* shape_infos, int thread_num) {
  36. if (model_type_ == "segmenter") {
  37. return seg_preprocess.Run(imgs, inputs, shape_infos, thread_num);
  38. } else if (model_type_ == "classifier") {
  39. return clas_preprocess.Run(imgs, inputs, shape_infos, thread_num);
  40. } else if (model_type_ == "detector") {
  41. return det_preprocess.Run(imgs, inputs, shape_infos, thread_num);
  42. } else {
  43. std::cerr << "[ERROR] Unexpected model_type: '"
  44. << model_type_ << "' in preprocess"
  45. << std::endl;
  46. return false;
  47. }
  48. return true;
  49. }
  50. } // namespace PaddleDeploy