1 /* Copyright 2018 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_TOOLS_OPTIMIZE_CALIBRATION_COMMON_H_ 16 #define TENSORFLOW_LITE_TOOLS_OPTIMIZE_CALIBRATION_COMMON_H_ 17 18 #include <unordered_map> 19 #include <unordered_set> 20 21 #include "tensorflow/lite/mutable_op_resolver.h" 22 23 namespace tflite { 24 namespace optimize { 25 namespace calibration { 26 using BuiltinOperatorKey = std::pair<BuiltinOperator, int>; 27 28 using BuiltinOpsSet = std::unordered_set< 29 BuiltinOperatorKey, 30 op_resolver_hasher::OperatorKeyHasher<BuiltinOperatorKey>>; 31 32 template <typename T> 33 class BuiltinOpsMap 34 : public std::unordered_map< 35 BuiltinOperatorKey, T, 36 op_resolver_hasher::OperatorKeyHasher<BuiltinOperatorKey>> {}; 37 38 // An alias for |TfLiteRegistration.invoke|. 39 using KernelEvalFuncPtr = TfLiteStatus (*)(TfLiteContext*, TfLiteNode*); 40 41 enum class OperatorTensorType { kNone, kInput, kOutput, kIntermediate }; 42 43 // Information about an operator in the TfLite graph. 44 struct OperatorInfo { 45 int node_index; 46 std::string name; 47 BuiltinOperator builtin_op_code; 48 bool is_custom_op; 49 std::vector<int> inputs; 50 std::vector<int> outputs; 51 // Inputs that need to be logged. 52 std::vector<int> loggable_inputs; 53 // Outputs that need to be logged. 54 std::vector<int> loggable_outputs; 55 const TfLiteRegistration* registration; 56 }; 57 58 } // namespace calibration 59 } // namespace optimize 60 } // namespace tflite 61 #endif // TENSORFLOW_LITE_TOOLS_OPTIMIZE_CALIBRATION_COMMON_H_ 62