• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CALIBRATION_COMMON_H_
16 #define TENSORFLOW_LITE_TOOLS_OPTIMIZE_CALIBRATION_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 CustomOperatorKey = std::pair<std::string, int>;
29 
30 using BuiltinOpsSet = std::unordered_set<
31     BuiltinOperatorKey,
32     op_resolver_hasher::OperatorKeyHasher<BuiltinOperatorKey>>;
33 
34 using CustomOpsSet = std::unordered_set<
35     CustomOperatorKey,
36     op_resolver_hasher::OperatorKeyHasher<CustomOperatorKey>>;
37 
38 template <typename T>
39 class BuiltinOpsMap
40     : public std::unordered_map<
41           BuiltinOperatorKey, T,
42           op_resolver_hasher::OperatorKeyHasher<BuiltinOperatorKey>> {};
43 
44 template <typename T>
45 class CustomOpsMap
46     : public std::unordered_map<
47           CustomOperatorKey, T,
48           op_resolver_hasher::OperatorKeyHasher<CustomOperatorKey>> {};
49 
50 // An alias for |TfLiteRegistration.invoke|.
51 using KernelEvalFuncPtr = TfLiteStatus (*)(TfLiteContext*, TfLiteNode*);
52 
53 enum class OperatorTensorType { kNone, kInput, kOutput, kIntermediate };
54 
55 // Information about an operator in the TfLite graph.
56 struct OperatorInfo {
57   int node_index;
58   std::string name;
59   BuiltinOperator builtin_op_code;
60   bool is_custom_op;
61   std::vector<int> inputs;
62   std::vector<int> outputs;
63   // Inputs that need to be logged.
64   std::vector<int> loggable_inputs;
65   // Outputs that need to be logged.
66   std::vector<int> loggable_outputs;
67   const TfLiteRegistration* registration;
68   int version;
69 };
70 
71 }  // namespace calibration
72 }  // namespace optimize
73 }  // namespace tflite
74 #endif  // TENSORFLOW_LITE_TOOLS_OPTIMIZE_CALIBRATION_CALIBRATION_COMMON_H_
75