x_postprocess.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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_postprocess.h"
  15. namespace PaddleDeploy {
  16. bool XPostprocess::Init(const YAML::Node& yaml_config) {
  17. model_type_ = yaml_config["model_type"].as<std::string>();
  18. if (model_type_ == "segmenter") {
  19. seg_post_process.Init(yaml_config);
  20. } else if (model_type_ == "detector") {
  21. det_post_process.Init(yaml_config);
  22. } else if (model_type_ == "classifier") {
  23. clas_post_process.Init(yaml_config);
  24. } else {
  25. std::cerr << "[ERROR] Unexpected model type '"
  26. << model_type_ << "' for PaddleX"
  27. << std::endl;
  28. return false;
  29. }
  30. return true;
  31. }
  32. bool XPostprocess::Run(const std::vector<DataBlob>& outputs,
  33. const std::vector<ShapeInfo>& shape_infos,
  34. std::vector<Result>* results, int thread_num) {
  35. results->clear();
  36. results->resize(shape_infos.size());
  37. if (model_type_ == "segmenter") {
  38. return seg_post_process.Run(outputs, shape_infos, results, thread_num);
  39. } else if (model_type_ == "classifier") {
  40. return clas_post_process.Run(outputs, shape_infos, results, thread_num);
  41. } else if (model_type_ == "detector") {
  42. return det_post_process.Run(outputs, shape_infos, results, thread_num);
  43. } else {
  44. std::cerr << "[ERROR] Unexpected model_type: '"
  45. << model_type_ << "' in postprocess"
  46. << std::endl;
  47. return false;
  48. }
  49. return true;
  50. }
  51. } // namespace PaddleDeploy