• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MINDSPORE_LITE_TOOLS_CONVERTER_CONFIG_PARSER_CONFIG_FILE_PARSER_H
18 #define MINDSPORE_LITE_TOOLS_CONVERTER_CONFIG_PARSER_CONFIG_FILE_PARSER_H
19 #include <string>
20 #include <map>
21 #include <vector>
22 
23 namespace mindspore {
24 namespace lite {
25 struct DataPreProcessString {
26   std::string calibrate_path;
27   std::string calibrate_size;
28   std::string input_type;
29   std::string image_to_format;
30   std::string normalize_mean;
31   std::string normalize_std;
32   std::string resize_width;
33   std::string resize_height;
34   std::string resize_method;
35   std::string center_crop_width;
36   std::string center_crop_height;
37 };
38 
39 struct CommonQuantString {
40   std::string quant_type;
41   std::string bit_num;
42   std::string min_quant_weight_size;
43   std::string min_quant_weight_channel;
44 };
45 
46 struct MixedBitWeightQuantString {
47   std::string init_scale;
48 };
49 
50 struct FullQuantString {
51   std::string activation_quant_method;
52   std::string bias_correction;
53 };
54 
55 struct RegistryInfoString {
56   std::string plugin_path;
57   std::string disable_fusion;
58 };
59 
60 class ConfigFileParser {
61  public:
62   int ParseConfigFile(const std::string &config_file_path);
63 
GetDataPreProcessString()64   DataPreProcessString GetDataPreProcessString() const { return this->data_pre_process_string_; }
GetCommonQuantString()65   CommonQuantString GetCommonQuantString() const { return this->common_quant_string_; }
GetMixedBitWeightQuantString()66   MixedBitWeightQuantString GetMixedBitWeightQuantString() const { return this->mixed_bit_quant_string_; }
GetFullQuantString()67   FullQuantString GetFullQuantString() const { return this->full_quant_string_; }
GetRegistryInfoString()68   RegistryInfoString GetRegistryInfoString() const { return this->registry_info_string_; }
69 
70  private:
71   int ParseDataPreProcessString(const std::map<std::string, std::map<std::string, std::string>> &maps);
72   int ParseCommonQuantString(const std::map<std::string, std::map<std::string, std::string>> &maps);
73   int ParseMixedBitQuantString(const std::map<std::string, std::map<std::string, std::string>> &maps);
74   int ParseFullQuantString(const std::map<std::string, std::map<std::string, std::string>> &maps);
75   int ParseRegistryInfoString(const std::map<std::string, std::map<std::string, std::string>> &maps);
76   int SetMapData(const std::map<std::string, std::string> &input_map,
77                  const std::map<std::string, std::string &> &parse_map, const std::string &section);
78 
79  private:
80   DataPreProcessString data_pre_process_string_;
81   CommonQuantString common_quant_string_;
82   MixedBitWeightQuantString mixed_bit_quant_string_;
83   FullQuantString full_quant_string_;
84   RegistryInfoString registry_info_string_;
85 };
86 
87 }  // namespace lite
88 }  // namespace mindspore
89 
90 #endif  // MINDSPORE_LITE_TOOLS_CONVERTER_CONFIG_PARSER_CONFIG_FILE_PARSER_H
91