2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "DataLookup.h"
18 #include "BuildBuiltinOptions.h"
20 namespace tflite2circle
23 circle::BuiltinOperator get_circle_builtin_code(tflite::BuiltinOperator tfl_bop)
27 #define TFL_OPERATOR(OP) \
28 case tflite::BuiltinOperator_##OP: \
29 return circle::BuiltinOperator_##OP;
30 #include "TFLOperator.lst"
33 throw std::runtime_error("tflite2circle: wrong op");
37 circle::TensorType get_circle_tensortype(tflite::TensorType tfl_tt)
41 #define TFL_TENSORTYPE(TENSORTYPE) \
42 case tflite::TensorType_##TENSORTYPE: \
43 return circle::TensorType_##TENSORTYPE;
44 #include "TFLTensorType.lst"
47 throw std::runtime_error("tflite2circle: wrong tensor type");
51 circle::Padding get_circle_padding(tflite::Padding tfl_p)
55 case tflite::Padding_SAME:
56 return circle::Padding_SAME;
57 case tflite::Padding_VALID:
58 return circle::Padding_VALID;
60 throw std::runtime_error("tflite2circle: wrong padding");
64 circle::ActivationFunctionType
65 get_circle_activation_function_type(tflite::ActivationFunctionType tfl_aft)
69 #define TFL_ACTIVATION_FUNCTION(TYPE) \
70 case tflite::ActivationFunctionType_##TYPE: \
71 return circle::ActivationFunctionType_##TYPE;
72 #include "TFLActivationFunctionType.lst"
73 #undef TFL_ACTIVATION_FUNCTION
75 throw std::runtime_error("tflite2circle: wrong activation function type.");
79 flatbuffers::Offset<void> get_circle_builtin_options(flatbuffers::FlatBufferBuilder &fb,
80 const tflite::Operator *op)
82 auto tflite_builtin_options_type = op->builtin_options_type();
83 switch (tflite_builtin_options_type)
85 case tflite::BuiltinOptions_NONE:
86 return flatbuffers::Offset<void>();
87 #define TFL_BUILTIN_OPTIONS(TYPE) \
88 case tflite::BuiltinOptions_##TYPE: \
89 return build_circle_##TYPE(fb, op).Union();
90 #include "TFLBuiltinOptions.lst"
91 #undef TFL_BUILTIN_OPTIONS
93 throw std::runtime_error("tflite2circle: wrong builtin options type.");
97 circle::BuiltinOptions get_circle_builtin_options_type(const tflite::Operator *op)
99 switch (op->builtin_options_type())
101 case tflite::BuiltinOptions_NONE:
102 return circle::BuiltinOptions_NONE;
103 #define TFL_BUILTIN_OPTIONS(TYPE) \
104 case tflite::BuiltinOptions_##TYPE: \
105 return circle::BuiltinOptions_##TYPE;
106 #include "TFLBuiltinOptions.lst"
107 #undef TFL_BUILTIN_OPTIONS
109 throw std::runtime_error("tflite2circle: wrong builtin options type.");
113 circle::MirrorPadMode get_circle_mirrorpad_mode(tflite::MirrorPadMode tfl_mode)
117 case tflite::MirrorPadMode_REFLECT:
118 return circle::MirrorPadMode_REFLECT;
119 case tflite::MirrorPadMode_SYMMETRIC:
120 return circle::MirrorPadMode_SYMMETRIC;
122 throw std::runtime_error("tflite2circle: wrong mirrorpad mode.");
126 } // namespace tflite2circle