1 /** 2 * Copyright 2021-2023 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_INCLUDE_REGISTRY_CONVERTER_CONTEXT_H_ 18 #define MINDSPORE_LITE_INCLUDE_REGISTRY_CONVERTER_CONTEXT_H_ 19 20 #include <map> 21 #include <string> 22 #include <vector> 23 #include "include/api/types.h" 24 #include "include/api/dual_abi_helper.h" 25 26 namespace mindspore { 27 namespace converter { 28 constexpr auto KConverterParam = "converter_parameters"; 29 constexpr auto KCommonQuantParam = "common_quant_param"; 30 constexpr auto KFullQuantParam = "full_quant_param"; 31 constexpr auto KDataPreProcess = "data_preprocess_param"; 32 constexpr auto KMixBitWeightQuantParam = "mixed_bit_weight_quant_param"; 33 34 /// \brief FmkType defined frameworks which converter tool supports. 35 enum MS_API FmkType : int { 36 kFmkTypeTf = 0, 37 kFmkTypeCaffe = 1, 38 kFmkTypeOnnx = 2, 39 kFmkTypeMs = 3, 40 kFmkTypeTflite = 4, 41 kFmkTypePytorch = 5, 42 kFmkTypeThirdParty = 6, 43 kFmkTypeOM = 7, 44 kFmkTypeMsLite = 8, 45 kFmkTypeEnd = 9, 46 }; 47 48 /// \brief ConverterParameters defined read-only converter parameters used by users in ModelParser. 49 struct MS_API ConverterParameters { 50 FmkType fmk; 51 ModelType save_type = kMindIR_Lite; 52 std::string model_file; 53 std::string weight_file; 54 std::map<std::string, std::string> attrs; 55 }; 56 57 /// \brief ConverterContext defined is to set the basic information of the exported model. 58 class MS_API ConverterContext { 59 public: 60 /// \brief Constructor. 61 ConverterContext() = default; 62 63 /// \brief Destructor. 64 ~ConverterContext() = default; 65 66 /// \brief Static method to set exported model's output name as needed by users. 67 /// 68 /// \param[in] output_names Define model's output name, the order of which is consistent with the original model. SetGraphOutputTensorNames(const std::vector<std::string> & output_names)69 static void SetGraphOutputTensorNames(const std::vector<std::string> &output_names) { 70 SetGraphOutputTensorNames(VectorStringToChar(output_names)); 71 } 72 73 /// \brief Static method to obtain the outputs' name. 74 /// 75 /// \return the outputs' name. GetGraphOutputTensorNames()76 static std::vector<std::string> GetGraphOutputTensorNames() { 77 return VectorCharToString(GetGraphOutputTensorNamesInChar()); 78 } 79 80 /// \brief Static method to get configure information which is used only by external extension. 81 /// 82 /// \param[in] section Define config section name. 83 /// 84 /// \return config key-value map. GetConfigInfo(const std::string & section)85 static std::map<std::string, std::string> GetConfigInfo(const std::string §ion) { 86 return MapVectorCharToString(GetConfigInfo(StringToChar(section))); 87 } 88 89 private: 90 static void SetGraphOutputTensorNames(const std::vector<std::vector<char>> &&output_names); 91 static std::vector<std::vector<char>> GetGraphOutputTensorNamesInChar(); 92 static std::map<std::vector<char>, std::vector<char>> GetConfigInfo(const std::vector<char> &§ion); 93 }; 94 } // namespace converter 95 } // namespace mindspore 96 97 #endif // MINDSPORE_LITE_INCLUDE_REGISTRY_CONVERTER_CONTEXT_H_ 98