model_infer.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 <gflags/gflags.h>
  15. #include <string>
  16. #include <vector>
  17. #include "model_deploy/common/include/paddle_deploy.h"
  18. DEFINE_string(model_filename, "", "Path of det inference model");
  19. DEFINE_string(params_filename, "", "Path of det inference params");
  20. DEFINE_string(cfg_file, "", "Path of yaml file");
  21. DEFINE_string(model_type, "", "model type");
  22. DEFINE_string(image, "", "Path of test image file");
  23. DEFINE_bool(use_gpu, false, "Infering with GPU or CPU");
  24. DEFINE_int32(gpu_id, 0, "GPU card id");
  25. DEFINE_string(key, "", "encrypt key");
  26. int main(int argc, char** argv) {
  27. // Parsing command-line
  28. google::ParseCommandLineFlags(&argc, &argv, true);
  29. // create model
  30. PaddleDeploy::Model* model = PaddleDeploy::CreateModel(FLAGS_model_type);
  31. // model init
  32. model->Init(FLAGS_cfg_file, FLAGS_key);
  33. // inference engine init
  34. PaddleDeploy::PaddleEngineConfig engine_config;
  35. engine_config.model_filename = FLAGS_model_filename;
  36. engine_config.params_filename = FLAGS_params_filename;
  37. engine_config.use_gpu = FLAGS_use_gpu;
  38. engine_config.gpu_id = FLAGS_gpu_id;
  39. engine_config.key = FLAGS_key;
  40. model->PaddleEngineInit(engine_config);
  41. // prepare data
  42. std::vector<cv::Mat> imgs;
  43. imgs.push_back(std::move(cv::imread(FLAGS_image)));
  44. // predict
  45. std::vector<PaddleDeploy::Result> results;
  46. model->Predict(imgs, &results, 1);
  47. std::cout << results[0] << std::endl;
  48. delete model;
  49. return 0;
  50. }