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_PREPROCESS_PARSER_H_ 18 #define MINDSPORE_LITE_TOOLS_CONVERTER_CONFIG_PARSER_PREPROCESS_PARSER_H_ 19 #include <string> 20 #include <map> 21 #include <vector> 22 #include "tools/converter/preprocess/preprocess_param.h" 23 #include "tools/converter/config_parser/config_file_parser.h" 24 25 namespace mindspore { 26 namespace lite { 27 constexpr int kDotDirCount = 2; 28 constexpr int kFileCountLimit = 100000; 29 class PreprocessParser { 30 public: 31 static int ParsePreprocess(const DataPreProcessString &data_pre_process_str, 32 preprocess::DataPreProcessParam *data_pre_process); 33 34 private: 35 static int ParseInputType(const std::string &input_type_str, preprocess::InputType *input_type); 36 37 static int ParseImagePreProcess(const DataPreProcessString &data_pre_process_str, 38 preprocess::ImagePreProcessParam *image_pre_process); 39 40 static int ParseImageNormalize(const DataPreProcessString &data_pre_process_str, 41 preprocess::ImagePreProcessParam *image_pre_process); 42 43 static int ParseImageResize(const DataPreProcessString &data_pre_process_str, 44 preprocess::ImagePreProcessParam *image_pre_process); 45 46 static int ParseImageCenterCrop(const DataPreProcessString &data_pre_process_str, 47 preprocess::ImagePreProcessParam *image_pre_process); 48 49 static int ParseImageToFormat(const std::string &image_to_format_str, preprocess::ImageToFormat *image_to_format); 50 51 static int ParseCalibratePath(const std::string &str, std::map<std::string, std::string> *value); 52 53 static int CollectCalibInputs(const std::map<std::string, std::string> &calibrate_data_path, size_t limited_count, 54 std::map<std::string, std::vector<std::string>> *inputs); 55 56 static int ReadDirectory(const std::string &path, std::vector<std::string> *file_names); 57 }; 58 } // namespace lite 59 } // namespace mindspore 60 #endif // MINDSPORE_LITE_TOOLS_CONVERTER_CONFIG_PARSER_PREPROCESS_PARSER_H_ 61