clas_model.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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/ppclas/include/clas_model.h"
  15. namespace PaddleDeploy {
  16. bool ClasModel::YamlConfigInit(const std::string& cfg_file,
  17. const std::string key) {
  18. if ("" == key) {
  19. yaml_config_ = YAML::LoadFile(cfg_file);
  20. } else {
  21. #ifdef PADDLEX_DEPLOY_ENCRYPTION
  22. std::string cfg = decrypt_file(cfg_file.c_str(), key.c_str());
  23. yaml_config_ = YAML::Load(cfg);
  24. #else
  25. std::cerr << "Don't open encryption on compile" << std::endl;
  26. return false;
  27. #endif // PADDLEX_DEPLOY_ENCRYPTION
  28. }
  29. return true;
  30. }
  31. bool ClasModel::PreprocessInit() {
  32. preprocess_ = std::make_shared<ClasPreprocess>();
  33. if (!preprocess_->Init(yaml_config_)) {
  34. return false;
  35. }
  36. return true;
  37. }
  38. bool ClasModel::PostprocessInit() {
  39. postprocess_ = std::make_shared<ClasPostprocess>();
  40. if (!postprocess_->Init(yaml_config_))
  41. return false;
  42. return true;
  43. }
  44. } // namespace PaddleDeploy