model_infer.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 <opencv2/core/core.hpp>
  18. #include <opencv2/highgui/highgui.hpp>
  19. #include <opencv2/imgproc/imgproc.hpp>
  20. #include "model_deploy/common/include/paddle_deploy.h"
  21. DEFINE_string(xml_file, "", "Path of model xml file");
  22. DEFINE_string(bin_file, "", "Path of model bin file");
  23. DEFINE_string(cfg_file, "", "Path of yaml file");
  24. DEFINE_string(model_type, "", "model type");
  25. DEFINE_string(image, "", "Path of test image file");
  26. DEFINE_string(device, "CPU", "Infering with VPU or CPU");
  27. int main(int argc, char** argv) {
  28. // Parsing command-line
  29. google::ParseCommandLineFlags(&argc, &argv, true);
  30. // create model
  31. PaddleDeploy::Model* model = PaddleDeploy::CreateModel(FLAGS_model_type);
  32. // model init
  33. model->Init(FLAGS_cfg_file);
  34. // engine init
  35. PaddleDeploy::OpenVinoEngineConfig engine_config;
  36. engine_config.xml_file_ = FLAGS_xml_file;
  37. engine_config.bin_file_ = FLAGS_bin_file;
  38. engine_config.batch_size_ = 1;
  39. engine_config.device_ = FLAGS_device;
  40. model->OpenVinoEngineInit(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. }