1 /* Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 #ifndef TENSORFLOW_LITE_TOCO_LOGGING_CONVERSION_LOG_UTIL_H_ 16 #define TENSORFLOW_LITE_TOCO_LOGGING_CONVERSION_LOG_UTIL_H_ 17 18 #include <map> 19 #include <string> 20 #include <vector> 21 22 #include "tensorflow/lite/toco/logging/toco_conversion_log.pb.h" 23 #include "tensorflow/lite/toco/model.h" 24 25 namespace toco { 26 27 // This function scans through the error message string, extracts the part about 28 // missing ops and prunes away all other information in the error info. 29 std::string SanitizeErrorMessage(const std::string& error_message); 30 31 // Populates the TocoConversionLog proto after analyzing the model. 32 void PopulateConversionLog(const Model& model, TocoConversionLog* log); 33 34 // Returns the names of the operators in the model. 35 std::vector<std::string> GetOperatorNames(const Model& model); 36 37 // Counts the number of different types of operators in the model: 38 // Built-in ops, custom ops and select ops. 39 // Each map is mapping from the name of the operator (such as 'Conv') to its 40 // total number of occurrences in the model. 41 void CountOperatorsByType(const Model& model, 42 std::map<std::string, int>* built_in_ops, 43 std::map<std::string, int>* custom_ops, 44 std::map<std::string, int>* select_ops); 45 46 // Gets the input and output types of the model. The input and output is 47 // specified by model.flags.input_arrays and model.flags.output_arrays. 48 void GetInputAndOutputTypes( 49 const Model& model, 50 TFLITE_PROTO_NS::RepeatedPtrField<std::string>* input_types, 51 TFLITE_PROTO_NS::RepeatedPtrField<std::string>* output_types); 52 53 // Calculates signatures for all the ops in the model. An op signature is 54 // defined by its input/output shapes and types, op name and its version. 55 void GetOpSignatures( 56 const Model& model, 57 TFLITE_PROTO_NS::RepeatedPtrField<std::string>* op_signatures); 58 59 // TODO(b/123519920): Implement this. 60 // Calculates a unique hash for the model. 61 std::string GetModelHash(const Model& model); 62 63 } // namespace toco 64 65 #endif // TENSORFLOW_LITE_TOCO_LOGGING_CONVERSION_LOG_UTIL_H_ 66