cls_config.h 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
// Copyright (c) 2020 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

#include <iomanip>
#include <iostream>
#include <map>
#include <ostream>
#include <string>
#include <vector>

#include "include/utility.h"

namespace PaddleClas {

L
littletomatodonkey 已提交
28
class ClsConfig {
29
public:
L
littletomatodonkey 已提交
30
  explicit ClsConfig(const std::string &config_file) {
31 32 33 34 35 36 37 38 39 40 41 42 43
    config_map_ = LoadConfig(config_file);

    this->use_gpu = bool(stoi(config_map_["use_gpu"]));

    this->gpu_id = stoi(config_map_["gpu_id"]);

    this->gpu_mem = stoi(config_map_["gpu_mem"]);

    this->cpu_math_library_num_threads =
        stoi(config_map_["cpu_math_library_num_threads"]);

    this->use_mkldnn = bool(stoi(config_map_["use_mkldnn"]));

L
littletomatodonkey 已提交
44 45 46
    this->use_tensorrt = bool(stoi(config_map_["use_tensorrt"]));
    this->use_fp16 = bool(stoi(config_map_["use_fp16"]));

47 48 49
    this->cls_model_path.assign(config_map_["cls_model_path"]);

    this->cls_params_path.assign(config_map_["cls_params_path"]);
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65

    this->resize_short_size = stoi(config_map_["resize_short_size"]);

    this->crop_size = stoi(config_map_["crop_size"]);
  }

  bool use_gpu = false;

  int gpu_id = 0;

  int gpu_mem = 4000;

  int cpu_math_library_num_threads = 1;

  bool use_mkldnn = false;

L
littletomatodonkey 已提交
66 67 68
  bool use_tensorrt = false;
  bool use_fp16 = false;

69 70 71
  std::string cls_model_path;

  std::string cls_params_path;
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88

  int resize_short_size = 256;
  int crop_size = 224;

  void PrintConfigInfo();

private:
  // Load configuration
  std::map<std::string, std::string> LoadConfig(const std::string &config_file);

  std::vector<std::string> split(const std::string &str,
                                 const std::string &delim);

  std::map<std::string, std::string> config_map_;
};

} // namespace PaddleClas