• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2020 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_LIST_FLEX_OPS_H_
16 #define TENSORFLOW_LITE_TOOLS_LIST_FLEX_OPS_H_
17 
18 #include <set>
19 #include <string>
20 
21 #include "tensorflow/lite/model.h"
22 
23 namespace tflite {
24 namespace flex {
25 
26 // Store the Op and Kernel name of an op as the key of a set or map.
27 struct OpKernel {
28   std::string op_name;
29   std::string kernel_name;
30 };
31 
32 // The comparison function for OpKernel.
33 struct OpKernelCompare {
operatorOpKernelCompare34   bool operator()(const OpKernel& lhs, const OpKernel& rhs) const {
35     if (lhs.op_name == rhs.op_name) {
36       return lhs.kernel_name < rhs.kernel_name;
37     }
38     return lhs.op_name < rhs.op_name;
39   }
40 };
41 
42 using OpKernelSet = std::set<OpKernel, OpKernelCompare>;
43 
44 // Find flex ops and its kernel classes inside a TFLite model and add them to
45 // the map flex_ops.
46 void AddFlexOpsFromModel(const tflite::Model* model, OpKernelSet* flex_ops);
47 
48 // Serialize the list op of to a json string. If flex_ops is empty, return an
49 // empty string.
50 std::string OpListToJSONString(const OpKernelSet& flex_ops);
51 
52 }  // namespace flex
53 }  // namespace tflite
54 
55 #endif  // TENSORFLOW_LITE_TOOLS_LIST_FLEX_OPS_H_
56