// Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. #pragma once #ifdef WIN32 #define OS_PATH_SEP "\\" #else #define OS_PATH_SEP "/" #endif #include "include/utility.h" #include "yaml-cpp/yaml.h" #include #include #include #include #include #include namespace PaddleClas { class ClsConfig { public: explicit ClsConfig(const std::string &path) { ReadYamlConfig(path); this->infer_imgs = this->config_file["Global"]["infer_imgs"].as(); this->batch_size = this->config_file["Global"]["batch_size"].as(); this->use_gpu = this->config_file["Global"]["use_gpu"].as(); if (this->config_file["Global"]["gpu_id"].IsDefined()) this->gpu_id = this->config_file["Global"]["gpu_id"].as(); else this->gpu_id = 0; this->gpu_mem = this->config_file["Global"]["gpu_mem"].as(); this->cpu_threads = this->config_file["Global"]["cpu_num_threads"].as(); this->use_mkldnn = this->config_file["Global"]["enable_mkldnn"].as(); this->use_tensorrt = this->config_file["Global"]["use_tensorrt"].as(); this->use_fp16 = this->config_file["Global"]["use_fp16"].as(); this->enable_benchmark = this->config_file["Global"]["enable_benchmark"].as(); this->ir_optim = this->config_file["Global"]["ir_optim"].as(); this->enable_profile = this->config_file["Global"]["enable_profile"].as(); this->cls_model_path = this->config_file["Global"]["inference_model_dir"].as() + OS_PATH_SEP + "inference.pdmodel"; this->cls_params_path = this->config_file["Global"]["inference_model_dir"].as() + OS_PATH_SEP + "inference.pdiparams"; this->resize_short_size = this->config_file["PreProcess"]["transform_ops"][0]["ResizeImage"] ["resize_short"] .as(); this->crop_size = this->config_file["PreProcess"]["transform_ops"][1]["CropImage"]["size"] .as(); this->scale = this->config_file["PreProcess"]["transform_ops"][2] ["NormalizeImage"]["scale"] .as(); this->mean = this->config_file["PreProcess"]["transform_ops"][2] ["NormalizeImage"]["mean"] .as>(); this->std = this->config_file["PreProcess"]["transform_ops"][2] ["NormalizeImage"]["std"] .as>(); if (this->config_file["Global"]["benchmark"].IsDefined()) this->benchmark = this->config_file["Global"]["benchmark"].as(); else this->benchmark = false; } YAML::Node config_file; bool use_gpu = false; int gpu_id = 0; int gpu_mem = 4000; int cpu_threads = 1; bool use_mkldnn = false; bool use_tensorrt = false; bool use_fp16 = false; bool benchmark = false; int batch_size = 1; bool enable_benchmark = false; bool ir_optim = true; bool enable_profile = false; std::string cls_model_path; std::string cls_params_path; std::string infer_imgs; int resize_short_size = 256; int crop_size = 224; float scale = 0.00392157; std::vector mean = {0.485, 0.456, 0.406}; std::vector std = {0.229, 0.224, 0.225}; void PrintConfigInfo(); void ReadYamlConfig(const std::string &path); }; } // namespace PaddleClas