• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TOOLS_VERSIONING_OP_VERSION_H_
16 #define TENSORFLOW_LITE_TOOLS_VERSIONING_OP_VERSION_H_
17 
18 #include <vector>
19 
20 #include "tensorflow/lite/schema/mutable/schema_generated.h"
21 
22 namespace tflite {
23 
24 // OpSignature contains operator parameters for version functions.
25 typedef struct {
26   BuiltinOperator op;
27   std::vector<TensorType> input_types;
28   std::vector<TensorType> output_types;
29   union {
30     struct {
31       int32_t dilation_w_factor;
32       int32_t dilation_h_factor;
33       bool is_per_channel_quantized;
34     } depthwise_conv_2d;
35     struct {
36       bool narrow_range;
37     } fakequant;
38     struct {
39       bool keep_num_dims;
40       FullyConnectedOptionsWeightsFormat weights_format;
41       // TODO(b/156530611): Make this global when more ops support sparse
42       // computation.
43       bool sparse_weight;
44       bool asymmetric_quantize_inputs;
45     } fully_connected;
46     struct {
47       float input1_scale;
48       float input2_scale;
49       float output_scale;
50     } mul;
51     struct {
52       LSTMKernelType kernel_type;
53       bool asymmetric_quantize_inputs;
54     } lstm;
55     struct {
56       bool half_pixel_centers;
57       bool align_corners;
58     } resize;
59     struct {
60       int32_t num_dims;
61     } single_input_op;
62     struct {
63       int32_t num_dims;
64       bool need_broadcast;
65     } broadcast;
66     struct {
67       bool pot_scale_int16;
68       int32_t num_dims;
69       bool need_broadcast;
70     } addsub;
71     struct {
72       bool is_per_channel_quantized;
73     } conv_2d;
74     struct {
75       bool asymmetric_quantize_inputs;
76     } input_quantization;
77   } options;
78 } OpSignature;
79 
80 // Returns version of builtin ops by the given signature.
81 int GetBuiltinOperatorVersion(const OpSignature& op_sig);
82 
83 // Update operator's version of the given TFL flatbuffer model.
84 void UpdateOpVersion(uint8_t* model_buffer_pointer);
85 
86 }  // namespace tflite
87 
88 #endif  // TENSORFLOW_LITE_TOOLS_VERSIONING_OP_VERSION_H_
89