From: 오형석/동작제어Lab(SR)/Senior Engineer/삼성전자 Date: Fri, 20 Apr 2018 09:28:08 +0000 (+0900) Subject: TFLite model tool: PEP8 Format (#821) X-Git-Tag: 0.1~162 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=92532b8aea8946c74141ab939c14d5d3f1ff95a4;p=platform%2Fcore%2Fml%2Fnnfw.git TFLite model tool: PEP8 Format (#821) Fix python code format based on PEP8 Signed-off-by: Hyeongseok Oh --- diff --git a/tools/tflitefile_tool/.FORMATCHECKED b/tools/tflitefile_tool/.FORMATCHECKED new file mode 100644 index 0000000..e69de29 diff --git a/tools/tflitefile_tool/model_parser.py b/tools/tflitefile_tool/model_parser.py index 11e2f12..6041c1e 100755 --- a/tools/tflitefile_tool/model_parser.py +++ b/tools/tflitefile_tool/model_parser.py @@ -4,7 +4,9 @@ import sys import numpy sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tflite')) -sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../externals/flatbuffers/python')) +sys.path.append( + os.path.join( + os.path.dirname(os.path.abspath(__file__)), '../../externals/flatbuffers/python')) import flatbuffers import tflite.Model @@ -17,6 +19,7 @@ import argparse BuiltinOpcodeStrList = {} + def SetBuiltinOpcodeStr(): BuiltinOpcodeStrList[0] = "ADD" BuiltinOpcodeStrList[1] = "AVERAGE_POOL_2D" @@ -71,6 +74,7 @@ def SetBuiltinOpcodeStr(): BuiltinOpcodeStrList[52] = "BIDIRECTIONAL_SEQUENCE_LSTM" BuiltinOpcodeStrList[53] = "CAST" + def PrintOperatorInfo(tf_model, tf_subgraph): print("Operators list\n") @@ -97,6 +101,7 @@ def PrintOperatorInfo(tf_model, tf_subgraph): print('') + def GetShapeStringFromTensor(tf_tensor): if tf_tensor.ShapeLength() == 0: return "Scalar" @@ -112,6 +117,7 @@ def GetShapeStringFromTensor(tf_tensor): return return_string + def PrintTensorInfo(tf_model, tf_subgraph): print("Tensor-Buffer mapping & shape\n") @@ -129,11 +135,13 @@ def PrintTensorInfo(tf_model, tf_subgraph): if tf_tensor.Name() != 0: shape_name = tf_tensor.Name() - print_str = "Tensor {0:4} : buffer {1:4} | {2} | Shape {3} | {4}".format(tensor_idx, buffer_idx, isEmpty, shape_str, shape_name) + print_str = "Tensor {0:4} : buffer {1:4} | {2} | Shape {3} | {4}".format( + tensor_idx, buffer_idx, isEmpty, shape_str, shape_name) print(print_str) print('') + def main(args): # Read flatbuffer file descriptor using argument tflite_file = args.input_file @@ -169,10 +177,12 @@ def main(args): # tensor and length of tensor PrintTensorInfo(tf_model, tf_subgraph) + if __name__ == '__main__': # Define argument and read arg_parser = argparse.ArgumentParser() - arg_parser.add_argument("input_file", type=argparse.FileType('rb'), help="tflite file to read") + arg_parser.add_argument( + "input_file", type=argparse.FileType('rb'), help="tflite file to read") args = arg_parser.parse_args() # Call main function diff --git a/tools/tflitefile_tool/select_operator.py b/tools/tflitefile_tool/select_operator.py index a451b6f..fa7a268 100755 --- a/tools/tflitefile_tool/select_operator.py +++ b/tools/tflitefile_tool/select_operator.py @@ -4,7 +4,9 @@ import sys import numpy sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tflite')) -sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../externals/flatbuffers/python')) +sys.path.append( + os.path.join( + os.path.dirname(os.path.abspath(__file__)), '../../externals/flatbuffers/python')) import flatbuffers import tflite.Model @@ -12,6 +14,7 @@ import tflite.SubGraph import tflite.BuiltinOptions import argparse + # Assume we use only main model in model file # Get selected operators from file, and return operator index list def GetOperatorList(oplist_file): @@ -25,7 +28,9 @@ def GetOperatorList(oplist_file): opcode_list.append(int(word)) else: print("Error: Cannot get operator list") - print("Please pass operators as operator index list split by space and/or line") + print( + "Please pass operators as operator index list split by space and/or line" + ) exit(1) if len(opcode_list) == 0: @@ -34,6 +39,7 @@ def GetOperatorList(oplist_file): return opcode_list + def GenerateOperatorCodes(new_builder, sample_model): operator_code_num = sample_model.OperatorCodesLength() new_operator_code_list = [] @@ -46,8 +52,10 @@ def GenerateOperatorCodes(new_builder, sample_model): for operator_code_idx in range(operator_code_num): operator_code = sample_model.OperatorCodes(operator_code_idx) operator_code_string = operator_code.CustomCode() - if (operator_code_string != "") and (not operator_code_string in new_operator_code_string_list): - new_operator_code_string_list[operator_code_string] = new_builder.CreateString(operator_code_string) + if (operator_code_string != + "") and (not operator_code_string in new_operator_code_string_list): + new_operator_code_string_list[ + operator_code_string] = new_builder.CreateString(operator_code_string) # Create tables of operator_code for operator_code_idx in range(operator_code_num): @@ -55,11 +63,13 @@ def GenerateOperatorCodes(new_builder, sample_model): # Create operator_code table tflite.OperatorCode.OperatorCodeStart(new_builder) - tflite.OperatorCode.OperatorCodeAddBuiltinCode(new_builder, operator_code.BuiltinCode()) + tflite.OperatorCode.OperatorCodeAddBuiltinCode(new_builder, + operator_code.BuiltinCode()) new_operator_code_string = operator_code.CustomCode() if new_operator_code_string in new_operator_code_string_list: - tflite.OperatorCode.OperatorCodeAddCustomCode(new_builder, new_operator_code_string_list[new_operator_code_string]) + tflite.OperatorCode.OperatorCodeAddCustomCode( + new_builder, new_operator_code_string_list[new_operator_code_string]) new_operator_code = tflite.OperatorCode.OperatorCodeEnd(new_builder) new_operator_code_list.append(new_operator_code) @@ -70,11 +80,13 @@ def GenerateOperatorCodes(new_builder, sample_model): return new_builder.EndVector(operator_code_num) + def GenerateQuantization(new_builder, selected_quantization): # Create min vector min_num = selected_quantization.MinLength() if min_num != 0: - tflite.QuantizationParameters.QuantizationParametersStartMinVector(new_builder, min_num) + tflite.QuantizationParameters.QuantizationParametersStartMinVector( + new_builder, min_num) for min_idx in reversed(range(min_num)): new_builder.PrependFloat32(selected_quantization.Min(min_idx)) new_min = new_builder.EndVector(min_num) @@ -82,7 +94,8 @@ def GenerateQuantization(new_builder, selected_quantization): # Create max vector max_num = selected_quantization.MaxLength() if max_num != 0: - tflite.QuantizationParameters.QuantizationParametersStartMaxVector(new_builder, max_num) + tflite.QuantizationParameters.QuantizationParametersStartMaxVector( + new_builder, max_num) for max_idx in reversed(range(max_num)): new_builder.PrependFloat32(selected_quantization.Max(max_idx)) new_max = new_builder.EndVector(max_num) @@ -90,7 +103,8 @@ def GenerateQuantization(new_builder, selected_quantization): # Create scale vector scale_num = selected_quantization.ScaleLength() if scale_num != 0: - tflite.QuantizationParameters.QuantizationParametersStartScaleVector(new_builder, scale_num) + tflite.QuantizationParameters.QuantizationParametersStartScaleVector( + new_builder, scale_num) for scale_idx in reversed(range(scale_num)): new_builder.PrependFloat32(selected_quantization.Scale(scale_idx)) new_scale = new_builder.EndVector(scale_num) @@ -98,7 +112,8 @@ def GenerateQuantization(new_builder, selected_quantization): # Create zero_point vector zeropoint_num = selected_quantization.ZeroPointLength() if zeropoint_num != 0: - tflite.QuantizationParameters.QuantizationParametersStartScaleVector(new_builder, zeropoint_num) + tflite.QuantizationParameters.QuantizationParametersStartScaleVector( + new_builder, zeropoint_num) for zeropoint_idx in reversed(range(zeropoint_num)): new_builder.PrependFloat32(selected_quantization.ZeroPoint(zeropoint_idx)) new_zeropoint = new_builder.EndVector(zeropoint_num) @@ -110,12 +125,15 @@ def GenerateQuantization(new_builder, selected_quantization): if max_num != 0: tflite.QuantizationParameters.QuantizationParametersAddMax(new_builder, new_max) if scale_num != 0: - tflite.QuantizationParameters.QuantizationParametersAddScale(new_builder, new_scale) + tflite.QuantizationParameters.QuantizationParametersAddScale( + new_builder, new_scale) if zeropoint_num != 0: - tflite.QuantizationParameters.QuantizationParametersAddZeroPoint(new_builder, new_zeropoint) + tflite.QuantizationParameters.QuantizationParametersAddZeroPoint( + new_builder, new_zeropoint) return tflite.QuantizationParameters.QuantizationParametersEnd(new_builder) + def GenerateTensor(new_builder, selected_tensor, used_buffers_dic): # Create shape vector for tensor @@ -156,6 +174,7 @@ def GenerateTensor(new_builder, selected_tensor, used_buffers_dic): return tflite.Tensor.TensorEnd(new_builder) + def GenerateTensors(new_builder, selected_subgraph, used_tensors_dic, used_buffers_dic): tensor_num = selected_subgraph.TensorsLength() new_tensor_list = [] @@ -179,6 +198,7 @@ def GenerateTensors(new_builder, selected_subgraph, used_tensors_dic, used_buffe return new_builder.EndVector(new_tensor_num) + import tflite.Conv2DOptions import tflite.DepthwiseConv2DOptions import tflite.Pool2DOptions @@ -187,6 +207,7 @@ import tflite.SoftmaxOptions import tflite.ConcatenationOptions import tflite.ReshapeOptions + def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_type): if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().Conv2DOptions: @@ -195,23 +216,34 @@ def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_t conv2d_options.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos) tflite.Conv2DOptions.Conv2DOptionsStart(new_builder) - tflite.Conv2DOptions.Conv2DOptionsAddPadding(new_builder, conv2d_options.Padding()) - tflite.Conv2DOptions.Conv2DOptionsAddStrideW(new_builder, conv2d_options.StrideW()) - tflite.Conv2DOptions.Conv2DOptionsAddStrideH(new_builder, conv2d_options.StrideH()) - tflite.Conv2DOptions.Conv2DOptionsAddFusedActivationFunction(new_builder, conv2d_options.FusedActivationFunction()) + tflite.Conv2DOptions.Conv2DOptionsAddPadding(new_builder, + conv2d_options.Padding()) + tflite.Conv2DOptions.Conv2DOptionsAddStrideW(new_builder, + conv2d_options.StrideW()) + tflite.Conv2DOptions.Conv2DOptionsAddStrideH(new_builder, + conv2d_options.StrideH()) + tflite.Conv2DOptions.Conv2DOptionsAddFusedActivationFunction( + new_builder, conv2d_options.FusedActivationFunction()) return tflite.Conv2DOptions.Conv2DOptionsEnd(new_builder) - if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().DepthwiseConv2DOptions: + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions( + ).DepthwiseConv2DOptions: depthconv2d_option = tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptions() - depthconv2d_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos) + depthconv2d_option.Init(selected_builtin_option.Bytes, + selected_builtin_option.Pos) tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsStart(new_builder) - tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsAddPadding(new_builder, depthconv2d_option.Padding()) - tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsAddStrideW(new_builder, depthconv2d_option.StrideW()) - tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsAddStrideH(new_builder, depthconv2d_option.StrideH()) - tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsAddDepthMultiplier(new_builder, depthconv2d_option.DepthMultiplier()) - tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsAddFusedActivationFunction(new_builder, depthconv2d_option.FusedActivationFunction()) + tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsAddPadding( + new_builder, depthconv2d_option.Padding()) + tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsAddStrideW( + new_builder, depthconv2d_option.StrideW()) + tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsAddStrideH( + new_builder, depthconv2d_option.StrideH()) + tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsAddDepthMultiplier( + new_builder, depthconv2d_option.DepthMultiplier()) + tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsAddFusedActivationFunction( + new_builder, depthconv2d_option.FusedActivationFunction()) return tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsEnd(new_builder) if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().Pool2DOptions: @@ -223,18 +255,23 @@ def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_t tflite.Pool2DOptions.Pool2DOptionsAddPadding(new_builder, pool2d_option.Padding()) tflite.Pool2DOptions.Pool2DOptionsAddStrideW(new_builder, pool2d_option.StrideW()) tflite.Pool2DOptions.Pool2DOptionsAddStrideH(new_builder, pool2d_option.StrideH()) - tflite.Pool2DOptions.Pool2DOptionsAddFilterWidth(new_builder, pool2d_option.FilterWidth()) - tflite.Pool2DOptions.Pool2DOptionsAddFilterHeight(new_builder, pool2d_option.FilterHeight()) - tflite.Pool2DOptions.Pool2DOptionsAddFusedActivationFunction(new_builder, pool2d_option.FusedActivationFunction()) + tflite.Pool2DOptions.Pool2DOptionsAddFilterWidth(new_builder, + pool2d_option.FilterWidth()) + tflite.Pool2DOptions.Pool2DOptionsAddFilterHeight(new_builder, + pool2d_option.FilterHeight()) + tflite.Pool2DOptions.Pool2DOptionsAddFusedActivationFunction( + new_builder, pool2d_option.FusedActivationFunction()) return tflite.Pool2DOptions.Pool2DOptionsEnd(new_builder) - if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().FullyConnectedOptions: + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions( + ).FullyConnectedOptions: fc_option = tflite.FullyConnectedOptions.FullyConnectedOptions() fc_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos) tflite.FullyConnectedOptions.FullyConnectedOptionsStart(new_builder) - tflite.FullyConnectedOptions.FullyConnectedOptionsAddFusedActivationFunction(new_builder, fc_option.FusedActivationFunction()) + tflite.FullyConnectedOptions.FullyConnectedOptionsAddFusedActivationFunction( + new_builder, fc_option.FusedActivationFunction()) return tflite.FullyConnectedOptions.FullyConnectedOptionsEnd(new_builder) if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().SoftmaxOptions: @@ -252,8 +289,10 @@ def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_t concat_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos) tflite.ConcatenationOptions.ConcatenationOptionsStart(new_builder) - tflite.ConcatenationOptions.ConcatenationOptionsAddAxis(new_builder, concat_option.Axis()) - tflite.ConcatenationOptions.ConcatenationOptionsAddFusedActivationFunction(new_builder, concat_option.FusedActivationFunction()) + tflite.ConcatenationOptions.ConcatenationOptionsAddAxis( + new_builder, concat_option.Axis()) + tflite.ConcatenationOptions.ConcatenationOptionsAddFusedActivationFunction( + new_builder, concat_option.FusedActivationFunction()) return tflite.ConcatenationOptions.ConcatenationOptionsEnd(new_builder) if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().ReshapeOptions: @@ -263,7 +302,8 @@ def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_t shape_num = reshape_option.NewShapeLength() if shape_num != 0: - tflite.ReshapeOptions.ReshapeOptionsStartNewShapeVector(new_builder, shape_num) + tflite.ReshapeOptions.ReshapeOptionsStartNewShapeVector( + new_builder, shape_num) for new_shape_idx in reversed(range(shape_num)): new_shape_val = reshape_option.NewShape(new_shape_idx) new_builder.PrependInt32(new_shape_val) @@ -277,6 +317,7 @@ def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_t # Cannot handle builtin option type yet return 0 + def GenerateOperator(new_builder, selected_operator, used_tensors_dic): # define opcode_index @@ -308,7 +349,8 @@ def GenerateOperator(new_builder, selected_operator, used_tensors_dic): builtin_option_type = selected_operator.BuiltinOptionsType() if builtin_option_type != 0: selected_builtin_option = selected_operator.BuiltinOptions() - new_builtin_option = GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_type) + new_builtin_option = GenerateBuiltinOption(new_builder, selected_builtin_option, + builtin_option_type) # Create custum option vector custom_option_num = selected_operator.CustomOptionsLength() @@ -332,10 +374,11 @@ def GenerateOperator(new_builder, selected_operator, used_tensors_dic): if builtin_option_type != 0: tflite.Operator.OperatorAddBuiltinOptions(new_builder, new_builtin_option) if custom_option_num != 0: - tflite.Operator.OperatorAddCustomOptions(new_builder,new_custom_option) + tflite.Operator.OperatorAddCustomOptions(new_builder, new_custom_option) tflite.Operator.OperatorAddCustomOptionsFormat(new_builder, custom_option_type) return tflite.Operator.OperatorEnd(new_builder) + def GenerateOperators(new_builder, selected_subgraph, opcode_list, used_tensors_dic): operator_num = selected_subgraph.OperatorsLength() new_operator_list = [] @@ -346,7 +389,8 @@ def GenerateOperators(new_builder, selected_subgraph, opcode_list, used_tensors_ for operator_idx in range(operator_num): if operator_idx in opcode_list: selected_operator = selected_subgraph.Operators(operator_idx) - new_operator = GenerateOperator(new_builder, selected_operator, used_tensors_dic) + new_operator = GenerateOperator(new_builder, selected_operator, + used_tensors_dic) new_operator_list.append(new_operator) new_operator_num = len(new_operator_list) @@ -359,10 +403,13 @@ def GenerateOperators(new_builder, selected_subgraph, opcode_list, used_tensors_ return new_builder.EndVector(new_operator_num) -def GenerateSubgraph(new_builder, selected_subgraph, opcode_list, new_input_tensor, new_output_tensor, used_tensors_dic, used_buffers_dic): + +def GenerateSubgraph(new_builder, selected_subgraph, opcode_list, new_input_tensor, + new_output_tensor, used_tensors_dic, used_buffers_dic): # Tensors - tensors = GenerateTensors(new_builder, selected_subgraph, used_tensors_dic, used_buffers_dic) + tensors = GenerateTensors(new_builder, selected_subgraph, used_tensors_dic, + used_buffers_dic) # Create input vector for subgraph table new_input_tensor_num = len(new_input_tensor) @@ -383,7 +430,8 @@ def GenerateSubgraph(new_builder, selected_subgraph, opcode_list, new_input_tens new_outputs = new_builder.EndVector(new_output_tensor_num) # Operators - operators = GenerateOperators(new_builder, selected_subgraph, opcode_list, used_tensors_dic) + operators = GenerateOperators(new_builder, selected_subgraph, opcode_list, + used_tensors_dic) # Name subgraph_name = selected_subgraph.Name() @@ -405,12 +453,15 @@ def GenerateSubgraph(new_builder, selected_subgraph, opcode_list, new_input_tens return tflite.SubGraph.SubGraphEnd(new_builder) -def GenerateSubgraphs(new_builder, sample_model, opcode_list, new_input_tensor, new_output_tensor, used_tensors_dic, used_buffers_dic): +def GenerateSubgraphs(new_builder, sample_model, opcode_list, new_input_tensor, + new_output_tensor, used_tensors_dic, used_buffers_dic): new_subgraph_list = [] # We think only main graph selected_subgraph = sample_model.Subgraphs(0) - new_subgraph = GenerateSubgraph(new_builder, selected_subgraph, opcode_list, new_input_tensor, new_output_tensor, used_tensors_dic, used_buffers_dic) + new_subgraph = GenerateSubgraph(new_builder, selected_subgraph, opcode_list, + new_input_tensor, new_output_tensor, used_tensors_dic, + used_buffers_dic) new_subgraph_list.append(new_subgraph) new_subgraph_num = 1 @@ -420,6 +471,7 @@ def GenerateSubgraphs(new_builder, sample_model, opcode_list, new_input_tensor, return new_builder.EndVector(new_subgraph_num) + def GenerateBuffers(new_builder, sample_model, used_buffers_dic): buffer_num = sample_model.BuffersLength() new_buffer_data_list = {} @@ -463,7 +515,9 @@ def GenerateBuffers(new_builder, sample_model, used_buffers_dic): return new_builder.EndVector(new_buffer_num) -def GenerateModel(new_builder, sample_model, opcode_list, new_input_tensors, new_output_tensors, used_tensors_dic, used_buffers_dic): + +def GenerateModel(new_builder, sample_model, opcode_list, new_input_tensors, + new_output_tensors, used_tensors_dic, used_buffers_dic): # uint version = sample_model.Version() @@ -471,7 +525,9 @@ def GenerateModel(new_builder, sample_model, opcode_list, new_input_tensors, new operator_codes = GenerateOperatorCodes(new_builder, sample_model) # subgraphs - subgraphs = GenerateSubgraphs(new_builder, sample_model, opcode_list, new_input_tensors, new_output_tensors, used_tensors_dic, used_buffers_dic) + subgraphs = GenerateSubgraphs(new_builder, sample_model, opcode_list, + new_input_tensors, new_output_tensors, used_tensors_dic, + used_buffers_dic) # description description_string = new_builder.CreateString(sample_model.Description()) @@ -489,11 +545,13 @@ def GenerateModel(new_builder, sample_model, opcode_list, new_input_tensors, new return tflite.Model.ModelEnd(new_builder) + def Finish(new_builder, new_model): # Cusrom implementation: identifier # Python API don't support identifier input yet # Reference: Finish(self, rootTable)) in builder.py, Finish(uoffset_t root, const char *file_identifier, bool size_prefix) in flatbuffers.h - new_builder.Prep(new_builder.minalign, flatbuffers.number_types.UOffsetTFlags.bytewidth) + new_builder.Prep(new_builder.minalign, + flatbuffers.number_types.UOffsetTFlags.bytewidth) new_builder.PrependByte(0x33) new_builder.PrependByte(0x4c) @@ -504,6 +562,7 @@ def Finish(new_builder, new_model): new_builder.finished = True return new_builder.Head() + def main(args): input_model_file = args.input_model oplist_file = args.opcode_list @@ -602,19 +661,28 @@ def main(args): # Create new model file new_builder = flatbuffers.Builder(1024) - new_model = GenerateModel(new_builder, sample_model, opcode_list, new_input_tensors, new_output_tensors, used_tensors_dic, used_buffers_dic) + new_model = GenerateModel(new_builder, sample_model, opcode_list, new_input_tensors, + new_output_tensors, used_tensors_dic, used_buffers_dic) Finish(new_builder, new_model) new_buf = new_builder.Output() output_model_file.write(new_buf) + if __name__ == '__main__': # Define argument and read arg_parser = argparse.ArgumentParser() - arg_parser.add_argument("input_model", type=argparse.FileType('rb'), help="input tflite model file to read") - arg_parser.add_argument("opcode_list", type=argparse.FileType('r'), help="text file including selected operator list") - arg_parser.add_argument("output_model", type=argparse.FileType('wb'), help="output tflite model file") + arg_parser.add_argument( + "input_model", + type=argparse.FileType('rb'), + help="input tflite model file to read") + arg_parser.add_argument( + "opcode_list", + type=argparse.FileType('r'), + help="text file including selected operator list") + arg_parser.add_argument( + "output_model", type=argparse.FileType('wb'), help="output tflite model file") args = arg_parser.parse_args() # Call main function diff --git a/tools/tflitefile_tool/tflite/ActivationFunctionType.py b/tools/tflitefile_tool/tflite/ActivationFunctionType.py index dc177de..a323539 100644 --- a/tools/tflitefile_tool/tflite/ActivationFunctionType.py +++ b/tools/tflitefile_tool/tflite/ActivationFunctionType.py @@ -2,6 +2,7 @@ # namespace: tflite + class ActivationFunctionType(object): NONE = 0 RELU = 1 @@ -9,4 +10,3 @@ class ActivationFunctionType(object): RELU6 = 3 TANH = 4 SIGN_BIT = 5 - diff --git a/tools/tflitefile_tool/tflite/AddOptions.py b/tools/tflitefile_tool/tflite/AddOptions.py index d6cbfcf..c9f3387 100644 --- a/tools/tflitefile_tool/tflite/AddOptions.py +++ b/tools/tflitefile_tool/tflite/AddOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class AddOptions(object): __slots__ = ['_tab'] @@ -25,6 +26,14 @@ class AddOptions(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def AddOptionsStart(builder): builder.StartObject(1) -def AddOptionsAddFusedActivationFunction(builder, fusedActivationFunction): builder.PrependInt8Slot(0, fusedActivationFunction, 0) -def AddOptionsEnd(builder): return builder.EndObject() + +def AddOptionsStart(builder): + builder.StartObject(1) + + +def AddOptionsAddFusedActivationFunction(builder, fusedActivationFunction): + builder.PrependInt8Slot(0, fusedActivationFunction, 0) + + +def AddOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/BatchToSpaceNDOptions.py b/tools/tflitefile_tool/tflite/BatchToSpaceNDOptions.py index 3ddcfd3..48a7d4c 100644 --- a/tools/tflitefile_tool/tflite/BatchToSpaceNDOptions.py +++ b/tools/tflitefile_tool/tflite/BatchToSpaceNDOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class BatchToSpaceNDOptions(object): __slots__ = ['_tab'] @@ -18,5 +19,10 @@ class BatchToSpaceNDOptions(object): def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) -def BatchToSpaceNDOptionsStart(builder): builder.StartObject(0) -def BatchToSpaceNDOptionsEnd(builder): return builder.EndObject() + +def BatchToSpaceNDOptionsStart(builder): + builder.StartObject(0) + + +def BatchToSpaceNDOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/BidirectionalSequenceRNNOptions.py b/tools/tflitefile_tool/tflite/BidirectionalSequenceRNNOptions.py index 8b32fcb..5c057b6 100644 --- a/tools/tflitefile_tool/tflite/BidirectionalSequenceRNNOptions.py +++ b/tools/tflitefile_tool/tflite/BidirectionalSequenceRNNOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class BidirectionalSequenceRNNOptions(object): __slots__ = ['_tab'] @@ -32,7 +33,19 @@ class BidirectionalSequenceRNNOptions(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def BidirectionalSequenceRNNOptionsStart(builder): builder.StartObject(2) -def BidirectionalSequenceRNNOptionsAddTimeMajor(builder, timeMajor): builder.PrependBoolSlot(0, timeMajor, 0) -def BidirectionalSequenceRNNOptionsAddFusedActivationFunction(builder, fusedActivationFunction): builder.PrependInt8Slot(1, fusedActivationFunction, 0) -def BidirectionalSequenceRNNOptionsEnd(builder): return builder.EndObject() + +def BidirectionalSequenceRNNOptionsStart(builder): + builder.StartObject(2) + + +def BidirectionalSequenceRNNOptionsAddTimeMajor(builder, timeMajor): + builder.PrependBoolSlot(0, timeMajor, 0) + + +def BidirectionalSequenceRNNOptionsAddFusedActivationFunction(builder, + fusedActivationFunction): + builder.PrependInt8Slot(1, fusedActivationFunction, 0) + + +def BidirectionalSequenceRNNOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/Buffer.py b/tools/tflitefile_tool/tflite/Buffer.py index 754dee3..d3fa8e9 100644 --- a/tools/tflitefile_tool/tflite/Buffer.py +++ b/tools/tflitefile_tool/tflite/Buffer.py @@ -4,6 +4,7 @@ import flatbuffers + class Buffer(object): __slots__ = ['_tab'] @@ -23,7 +24,9 @@ class Buffer(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) if o != 0: a = self._tab.Vector(o) - return self._tab.Get(flatbuffers.number_types.Uint8Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 1)) + return self._tab.Get( + flatbuffers.number_types.Uint8Flags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 1)) return 0 # Buffer @@ -40,7 +43,19 @@ class Buffer(object): return self._tab.VectorLen(o) return 0 -def BufferStart(builder): builder.StartObject(1) -def BufferAddData(builder, data): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(data), 0) -def BufferStartDataVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def BufferEnd(builder): return builder.EndObject() + +def BufferStart(builder): + builder.StartObject(1) + + +def BufferAddData(builder, data): + builder.PrependUOffsetTRelativeSlot( + 0, flatbuffers.number_types.UOffsetTFlags.py_type(data), 0) + + +def BufferStartDataVector(builder, numElems): + return builder.StartVector(1, numElems, 1) + + +def BufferEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/BuiltinOperator.py b/tools/tflitefile_tool/tflite/BuiltinOperator.py index f0bad0a..5ab8d9f 100644 --- a/tools/tflitefile_tool/tflite/BuiltinOperator.py +++ b/tools/tflitefile_tool/tflite/BuiltinOperator.py @@ -2,6 +2,7 @@ # namespace: tflite + class BuiltinOperator(object): ADD = 0 AVERAGE_POOL_2D = 1 @@ -55,4 +56,3 @@ class BuiltinOperator(object): DELEGATE = 51 BIDIRECTIONAL_SEQUENCE_LSTM = 52 CAST = 53 - diff --git a/tools/tflitefile_tool/tflite/BuiltinOptions.py b/tools/tflitefile_tool/tflite/BuiltinOptions.py index 92f1816..3883217 100644 --- a/tools/tflitefile_tool/tflite/BuiltinOptions.py +++ b/tools/tflitefile_tool/tflite/BuiltinOptions.py @@ -2,6 +2,7 @@ # namespace: tflite + class BuiltinOptions(object): NONE = 0 Conv2DOptions = 1 @@ -42,4 +43,3 @@ class BuiltinOptions(object): LogSoftmaxOptions = 36 CastOptions = 37 DequantizeOptions = 38 - diff --git a/tools/tflitefile_tool/tflite/CallOptions.py b/tools/tflitefile_tool/tflite/CallOptions.py index 5ae2eea..a82f001 100644 --- a/tools/tflitefile_tool/tflite/CallOptions.py +++ b/tools/tflitefile_tool/tflite/CallOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class CallOptions(object): __slots__ = ['_tab'] @@ -25,6 +26,14 @@ class CallOptions(object): return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos) return 0 -def CallOptionsStart(builder): builder.StartObject(1) -def CallOptionsAddSubgraph(builder, subgraph): builder.PrependUint32Slot(0, subgraph, 0) -def CallOptionsEnd(builder): return builder.EndObject() + +def CallOptionsStart(builder): + builder.StartObject(1) + + +def CallOptionsAddSubgraph(builder, subgraph): + builder.PrependUint32Slot(0, subgraph, 0) + + +def CallOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/CastOptions.py b/tools/tflitefile_tool/tflite/CastOptions.py index e943f9f..13e76bb 100644 --- a/tools/tflitefile_tool/tflite/CastOptions.py +++ b/tools/tflitefile_tool/tflite/CastOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class CastOptions(object): __slots__ = ['_tab'] @@ -18,5 +19,10 @@ class CastOptions(object): def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) -def CastOptionsStart(builder): builder.StartObject(0) -def CastOptionsEnd(builder): return builder.EndObject() + +def CastOptionsStart(builder): + builder.StartObject(0) + + +def CastOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/CombinerType.py b/tools/tflitefile_tool/tflite/CombinerType.py index 17d9151..dfe8afb 100644 --- a/tools/tflitefile_tool/tflite/CombinerType.py +++ b/tools/tflitefile_tool/tflite/CombinerType.py @@ -2,8 +2,8 @@ # namespace: tflite + class CombinerType(object): SUM = 0 MEAN = 1 SQRTN = 2 - diff --git a/tools/tflitefile_tool/tflite/ConcatEmbeddingsOptions.py b/tools/tflitefile_tool/tflite/ConcatEmbeddingsOptions.py index 9d26c51..6ca04a5 100644 --- a/tools/tflitefile_tool/tflite/ConcatEmbeddingsOptions.py +++ b/tools/tflitefile_tool/tflite/ConcatEmbeddingsOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class ConcatEmbeddingsOptions(object): __slots__ = ['_tab'] @@ -30,7 +31,9 @@ class ConcatEmbeddingsOptions(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) if o != 0: a = self._tab.Vector(o) - return self._tab.Get(flatbuffers.number_types.Int32Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return self._tab.Get( + flatbuffers.number_types.Int32Flags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) return 0 # ConcatEmbeddingsOptions @@ -52,7 +55,9 @@ class ConcatEmbeddingsOptions(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) if o != 0: a = self._tab.Vector(o) - return self._tab.Get(flatbuffers.number_types.Int32Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return self._tab.Get( + flatbuffers.number_types.Int32Flags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) return 0 # ConcatEmbeddingsOptions @@ -69,10 +74,32 @@ class ConcatEmbeddingsOptions(object): return self._tab.VectorLen(o) return 0 -def ConcatEmbeddingsOptionsStart(builder): builder.StartObject(3) -def ConcatEmbeddingsOptionsAddNumChannels(builder, numChannels): builder.PrependInt32Slot(0, numChannels, 0) -def ConcatEmbeddingsOptionsAddNumColumnsPerChannel(builder, numColumnsPerChannel): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(numColumnsPerChannel), 0) -def ConcatEmbeddingsOptionsStartNumColumnsPerChannelVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def ConcatEmbeddingsOptionsAddEmbeddingDimPerChannel(builder, embeddingDimPerChannel): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(embeddingDimPerChannel), 0) -def ConcatEmbeddingsOptionsStartEmbeddingDimPerChannelVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def ConcatEmbeddingsOptionsEnd(builder): return builder.EndObject() + +def ConcatEmbeddingsOptionsStart(builder): + builder.StartObject(3) + + +def ConcatEmbeddingsOptionsAddNumChannels(builder, numChannels): + builder.PrependInt32Slot(0, numChannels, 0) + + +def ConcatEmbeddingsOptionsAddNumColumnsPerChannel(builder, numColumnsPerChannel): + builder.PrependUOffsetTRelativeSlot( + 1, flatbuffers.number_types.UOffsetTFlags.py_type(numColumnsPerChannel), 0) + + +def ConcatEmbeddingsOptionsStartNumColumnsPerChannelVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def ConcatEmbeddingsOptionsAddEmbeddingDimPerChannel(builder, embeddingDimPerChannel): + builder.PrependUOffsetTRelativeSlot( + 2, flatbuffers.number_types.UOffsetTFlags.py_type(embeddingDimPerChannel), 0) + + +def ConcatEmbeddingsOptionsStartEmbeddingDimPerChannelVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def ConcatEmbeddingsOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/ConcatenationOptions.py b/tools/tflitefile_tool/tflite/ConcatenationOptions.py index c8e0b6a..ea089ac 100644 --- a/tools/tflitefile_tool/tflite/ConcatenationOptions.py +++ b/tools/tflitefile_tool/tflite/ConcatenationOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class ConcatenationOptions(object): __slots__ = ['_tab'] @@ -32,7 +33,18 @@ class ConcatenationOptions(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def ConcatenationOptionsStart(builder): builder.StartObject(2) -def ConcatenationOptionsAddAxis(builder, axis): builder.PrependInt32Slot(0, axis, 0) -def ConcatenationOptionsAddFusedActivationFunction(builder, fusedActivationFunction): builder.PrependInt8Slot(1, fusedActivationFunction, 0) -def ConcatenationOptionsEnd(builder): return builder.EndObject() + +def ConcatenationOptionsStart(builder): + builder.StartObject(2) + + +def ConcatenationOptionsAddAxis(builder, axis): + builder.PrependInt32Slot(0, axis, 0) + + +def ConcatenationOptionsAddFusedActivationFunction(builder, fusedActivationFunction): + builder.PrependInt8Slot(1, fusedActivationFunction, 0) + + +def ConcatenationOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/Conv2DOptions.py b/tools/tflitefile_tool/tflite/Conv2DOptions.py index 004e400..e204a76 100644 --- a/tools/tflitefile_tool/tflite/Conv2DOptions.py +++ b/tools/tflitefile_tool/tflite/Conv2DOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class Conv2DOptions(object): __slots__ = ['_tab'] @@ -46,9 +47,26 @@ class Conv2DOptions(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def Conv2DOptionsStart(builder): builder.StartObject(4) -def Conv2DOptionsAddPadding(builder, padding): builder.PrependInt8Slot(0, padding, 0) -def Conv2DOptionsAddStrideW(builder, strideW): builder.PrependInt32Slot(1, strideW, 0) -def Conv2DOptionsAddStrideH(builder, strideH): builder.PrependInt32Slot(2, strideH, 0) -def Conv2DOptionsAddFusedActivationFunction(builder, fusedActivationFunction): builder.PrependInt8Slot(3, fusedActivationFunction, 0) -def Conv2DOptionsEnd(builder): return builder.EndObject() + +def Conv2DOptionsStart(builder): + builder.StartObject(4) + + +def Conv2DOptionsAddPadding(builder, padding): + builder.PrependInt8Slot(0, padding, 0) + + +def Conv2DOptionsAddStrideW(builder, strideW): + builder.PrependInt32Slot(1, strideW, 0) + + +def Conv2DOptionsAddStrideH(builder, strideH): + builder.PrependInt32Slot(2, strideH, 0) + + +def Conv2DOptionsAddFusedActivationFunction(builder, fusedActivationFunction): + builder.PrependInt8Slot(3, fusedActivationFunction, 0) + + +def Conv2DOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/CustomOptionsFormat.py b/tools/tflitefile_tool/tflite/CustomOptionsFormat.py index bef384c..18bc07d 100644 --- a/tools/tflitefile_tool/tflite/CustomOptionsFormat.py +++ b/tools/tflitefile_tool/tflite/CustomOptionsFormat.py @@ -2,6 +2,6 @@ # namespace: tflite + class CustomOptionsFormat(object): FLEXBUFFERS = 0 - diff --git a/tools/tflitefile_tool/tflite/DepthwiseConv2DOptions.py b/tools/tflitefile_tool/tflite/DepthwiseConv2DOptions.py index 002d583..9f0b338 100644 --- a/tools/tflitefile_tool/tflite/DepthwiseConv2DOptions.py +++ b/tools/tflitefile_tool/tflite/DepthwiseConv2DOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class DepthwiseConv2DOptions(object): __slots__ = ['_tab'] @@ -53,10 +54,30 @@ class DepthwiseConv2DOptions(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def DepthwiseConv2DOptionsStart(builder): builder.StartObject(5) -def DepthwiseConv2DOptionsAddPadding(builder, padding): builder.PrependInt8Slot(0, padding, 0) -def DepthwiseConv2DOptionsAddStrideW(builder, strideW): builder.PrependInt32Slot(1, strideW, 0) -def DepthwiseConv2DOptionsAddStrideH(builder, strideH): builder.PrependInt32Slot(2, strideH, 0) -def DepthwiseConv2DOptionsAddDepthMultiplier(builder, depthMultiplier): builder.PrependInt32Slot(3, depthMultiplier, 0) -def DepthwiseConv2DOptionsAddFusedActivationFunction(builder, fusedActivationFunction): builder.PrependInt8Slot(4, fusedActivationFunction, 0) -def DepthwiseConv2DOptionsEnd(builder): return builder.EndObject() + +def DepthwiseConv2DOptionsStart(builder): + builder.StartObject(5) + + +def DepthwiseConv2DOptionsAddPadding(builder, padding): + builder.PrependInt8Slot(0, padding, 0) + + +def DepthwiseConv2DOptionsAddStrideW(builder, strideW): + builder.PrependInt32Slot(1, strideW, 0) + + +def DepthwiseConv2DOptionsAddStrideH(builder, strideH): + builder.PrependInt32Slot(2, strideH, 0) + + +def DepthwiseConv2DOptionsAddDepthMultiplier(builder, depthMultiplier): + builder.PrependInt32Slot(3, depthMultiplier, 0) + + +def DepthwiseConv2DOptionsAddFusedActivationFunction(builder, fusedActivationFunction): + builder.PrependInt8Slot(4, fusedActivationFunction, 0) + + +def DepthwiseConv2DOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/DequantizeOptions.py b/tools/tflitefile_tool/tflite/DequantizeOptions.py index 5ef8b8d..fe4cc9a 100644 --- a/tools/tflitefile_tool/tflite/DequantizeOptions.py +++ b/tools/tflitefile_tool/tflite/DequantizeOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class DequantizeOptions(object): __slots__ = ['_tab'] @@ -18,5 +19,10 @@ class DequantizeOptions(object): def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) -def DequantizeOptionsStart(builder): builder.StartObject(0) -def DequantizeOptionsEnd(builder): return builder.EndObject() + +def DequantizeOptionsStart(builder): + builder.StartObject(0) + + +def DequantizeOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/DivOptions.py b/tools/tflitefile_tool/tflite/DivOptions.py index 905a3be..53bbae5 100644 --- a/tools/tflitefile_tool/tflite/DivOptions.py +++ b/tools/tflitefile_tool/tflite/DivOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class DivOptions(object): __slots__ = ['_tab'] @@ -25,6 +26,14 @@ class DivOptions(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def DivOptionsStart(builder): builder.StartObject(1) -def DivOptionsAddFusedActivationFunction(builder, fusedActivationFunction): builder.PrependInt8Slot(0, fusedActivationFunction, 0) -def DivOptionsEnd(builder): return builder.EndObject() + +def DivOptionsStart(builder): + builder.StartObject(1) + + +def DivOptionsAddFusedActivationFunction(builder, fusedActivationFunction): + builder.PrependInt8Slot(0, fusedActivationFunction, 0) + + +def DivOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/EmbeddingLookupSparseOptions.py b/tools/tflitefile_tool/tflite/EmbeddingLookupSparseOptions.py index 7d9c144..12531d3 100644 --- a/tools/tflitefile_tool/tflite/EmbeddingLookupSparseOptions.py +++ b/tools/tflitefile_tool/tflite/EmbeddingLookupSparseOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class EmbeddingLookupSparseOptions(object): __slots__ = ['_tab'] @@ -25,6 +26,14 @@ class EmbeddingLookupSparseOptions(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def EmbeddingLookupSparseOptionsStart(builder): builder.StartObject(1) -def EmbeddingLookupSparseOptionsAddCombiner(builder, combiner): builder.PrependInt8Slot(0, combiner, 0) -def EmbeddingLookupSparseOptionsEnd(builder): return builder.EndObject() + +def EmbeddingLookupSparseOptionsStart(builder): + builder.StartObject(1) + + +def EmbeddingLookupSparseOptionsAddCombiner(builder, combiner): + builder.PrependInt8Slot(0, combiner, 0) + + +def EmbeddingLookupSparseOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/ExpOptions.py b/tools/tflitefile_tool/tflite/ExpOptions.py index eac1456..f8c7bd8 100644 --- a/tools/tflitefile_tool/tflite/ExpOptions.py +++ b/tools/tflitefile_tool/tflite/ExpOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class ExpOptions(object): __slots__ = ['_tab'] @@ -18,5 +19,10 @@ class ExpOptions(object): def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) -def ExpOptionsStart(builder): builder.StartObject(0) -def ExpOptionsEnd(builder): return builder.EndObject() + +def ExpOptionsStart(builder): + builder.StartObject(0) + + +def ExpOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/FullyConnectedOptions.py b/tools/tflitefile_tool/tflite/FullyConnectedOptions.py index ffab6b8..366c5e8 100644 --- a/tools/tflitefile_tool/tflite/FullyConnectedOptions.py +++ b/tools/tflitefile_tool/tflite/FullyConnectedOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class FullyConnectedOptions(object): __slots__ = ['_tab'] @@ -25,6 +26,14 @@ class FullyConnectedOptions(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def FullyConnectedOptionsStart(builder): builder.StartObject(1) -def FullyConnectedOptionsAddFusedActivationFunction(builder, fusedActivationFunction): builder.PrependInt8Slot(0, fusedActivationFunction, 0) -def FullyConnectedOptionsEnd(builder): return builder.EndObject() + +def FullyConnectedOptionsStart(builder): + builder.StartObject(1) + + +def FullyConnectedOptionsAddFusedActivationFunction(builder, fusedActivationFunction): + builder.PrependInt8Slot(0, fusedActivationFunction, 0) + + +def FullyConnectedOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/GatherOptions.py b/tools/tflitefile_tool/tflite/GatherOptions.py index 9fbc3e4..cfb5449 100644 --- a/tools/tflitefile_tool/tflite/GatherOptions.py +++ b/tools/tflitefile_tool/tflite/GatherOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class GatherOptions(object): __slots__ = ['_tab'] @@ -25,6 +26,14 @@ class GatherOptions(object): return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) return 0 -def GatherOptionsStart(builder): builder.StartObject(1) -def GatherOptionsAddAxis(builder, axis): builder.PrependInt32Slot(0, axis, 0) -def GatherOptionsEnd(builder): return builder.EndObject() + +def GatherOptionsStart(builder): + builder.StartObject(1) + + +def GatherOptionsAddAxis(builder, axis): + builder.PrependInt32Slot(0, axis, 0) + + +def GatherOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/L2NormOptions.py b/tools/tflitefile_tool/tflite/L2NormOptions.py index 38bdf57..1d3ab1e 100644 --- a/tools/tflitefile_tool/tflite/L2NormOptions.py +++ b/tools/tflitefile_tool/tflite/L2NormOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class L2NormOptions(object): __slots__ = ['_tab'] @@ -25,6 +26,14 @@ class L2NormOptions(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def L2NormOptionsStart(builder): builder.StartObject(1) -def L2NormOptionsAddFusedActivationFunction(builder, fusedActivationFunction): builder.PrependInt8Slot(0, fusedActivationFunction, 0) -def L2NormOptionsEnd(builder): return builder.EndObject() + +def L2NormOptionsStart(builder): + builder.StartObject(1) + + +def L2NormOptionsAddFusedActivationFunction(builder, fusedActivationFunction): + builder.PrependInt8Slot(0, fusedActivationFunction, 0) + + +def L2NormOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/LSHProjectionOptions.py b/tools/tflitefile_tool/tflite/LSHProjectionOptions.py index ad550be..055eb75 100644 --- a/tools/tflitefile_tool/tflite/LSHProjectionOptions.py +++ b/tools/tflitefile_tool/tflite/LSHProjectionOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class LSHProjectionOptions(object): __slots__ = ['_tab'] @@ -25,6 +26,14 @@ class LSHProjectionOptions(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def LSHProjectionOptionsStart(builder): builder.StartObject(1) -def LSHProjectionOptionsAddType(builder, type): builder.PrependInt8Slot(0, type, 0) -def LSHProjectionOptionsEnd(builder): return builder.EndObject() + +def LSHProjectionOptionsStart(builder): + builder.StartObject(1) + + +def LSHProjectionOptionsAddType(builder, type): + builder.PrependInt8Slot(0, type, 0) + + +def LSHProjectionOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/LSHProjectionType.py b/tools/tflitefile_tool/tflite/LSHProjectionType.py index d6a136e..3281791 100644 --- a/tools/tflitefile_tool/tflite/LSHProjectionType.py +++ b/tools/tflitefile_tool/tflite/LSHProjectionType.py @@ -2,8 +2,8 @@ # namespace: tflite + class LSHProjectionType(object): UNKNOWN = 0 SPARSE = 1 DENSE = 2 - diff --git a/tools/tflitefile_tool/tflite/LSTMOptions.py b/tools/tflitefile_tool/tflite/LSTMOptions.py index 06c43ec..f9a44f5 100644 --- a/tools/tflitefile_tool/tflite/LSTMOptions.py +++ b/tools/tflitefile_tool/tflite/LSTMOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class LSTMOptions(object): __slots__ = ['_tab'] @@ -39,8 +40,22 @@ class LSTMOptions(object): return self._tab.Get(flatbuffers.number_types.Float32Flags, o + self._tab.Pos) return 0.0 -def LSTMOptionsStart(builder): builder.StartObject(3) -def LSTMOptionsAddFusedActivationFunction(builder, fusedActivationFunction): builder.PrependInt8Slot(0, fusedActivationFunction, 0) -def LSTMOptionsAddCellClip(builder, cellClip): builder.PrependFloat32Slot(1, cellClip, 0.0) -def LSTMOptionsAddProjClip(builder, projClip): builder.PrependFloat32Slot(2, projClip, 0.0) -def LSTMOptionsEnd(builder): return builder.EndObject() + +def LSTMOptionsStart(builder): + builder.StartObject(3) + + +def LSTMOptionsAddFusedActivationFunction(builder, fusedActivationFunction): + builder.PrependInt8Slot(0, fusedActivationFunction, 0) + + +def LSTMOptionsAddCellClip(builder, cellClip): + builder.PrependFloat32Slot(1, cellClip, 0.0) + + +def LSTMOptionsAddProjClip(builder, projClip): + builder.PrependFloat32Slot(2, projClip, 0.0) + + +def LSTMOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/LocalResponseNormalizationOptions.py b/tools/tflitefile_tool/tflite/LocalResponseNormalizationOptions.py index db87560..fd9117a 100644 --- a/tools/tflitefile_tool/tflite/LocalResponseNormalizationOptions.py +++ b/tools/tflitefile_tool/tflite/LocalResponseNormalizationOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class LocalResponseNormalizationOptions(object): __slots__ = ['_tab'] @@ -46,9 +47,26 @@ class LocalResponseNormalizationOptions(object): return self._tab.Get(flatbuffers.number_types.Float32Flags, o + self._tab.Pos) return 0.0 -def LocalResponseNormalizationOptionsStart(builder): builder.StartObject(4) -def LocalResponseNormalizationOptionsAddRadius(builder, radius): builder.PrependInt32Slot(0, radius, 0) -def LocalResponseNormalizationOptionsAddBias(builder, bias): builder.PrependFloat32Slot(1, bias, 0.0) -def LocalResponseNormalizationOptionsAddAlpha(builder, alpha): builder.PrependFloat32Slot(2, alpha, 0.0) -def LocalResponseNormalizationOptionsAddBeta(builder, beta): builder.PrependFloat32Slot(3, beta, 0.0) -def LocalResponseNormalizationOptionsEnd(builder): return builder.EndObject() + +def LocalResponseNormalizationOptionsStart(builder): + builder.StartObject(4) + + +def LocalResponseNormalizationOptionsAddRadius(builder, radius): + builder.PrependInt32Slot(0, radius, 0) + + +def LocalResponseNormalizationOptionsAddBias(builder, bias): + builder.PrependFloat32Slot(1, bias, 0.0) + + +def LocalResponseNormalizationOptionsAddAlpha(builder, alpha): + builder.PrependFloat32Slot(2, alpha, 0.0) + + +def LocalResponseNormalizationOptionsAddBeta(builder, beta): + builder.PrependFloat32Slot(3, beta, 0.0) + + +def LocalResponseNormalizationOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/LogSoftmaxOptions.py b/tools/tflitefile_tool/tflite/LogSoftmaxOptions.py index 4789385..1b059d2 100644 --- a/tools/tflitefile_tool/tflite/LogSoftmaxOptions.py +++ b/tools/tflitefile_tool/tflite/LogSoftmaxOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class LogSoftmaxOptions(object): __slots__ = ['_tab'] @@ -18,5 +19,10 @@ class LogSoftmaxOptions(object): def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) -def LogSoftmaxOptionsStart(builder): builder.StartObject(0) -def LogSoftmaxOptionsEnd(builder): return builder.EndObject() + +def LogSoftmaxOptionsStart(builder): + builder.StartObject(0) + + +def LogSoftmaxOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/MeanOptions.py b/tools/tflitefile_tool/tflite/MeanOptions.py index d884e05..9d49119 100644 --- a/tools/tflitefile_tool/tflite/MeanOptions.py +++ b/tools/tflitefile_tool/tflite/MeanOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class MeanOptions(object): __slots__ = ['_tab'] @@ -25,6 +26,14 @@ class MeanOptions(object): return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos) return 0 -def MeanOptionsStart(builder): builder.StartObject(1) -def MeanOptionsAddKeepDims(builder, keepDims): builder.PrependBoolSlot(0, keepDims, 0) -def MeanOptionsEnd(builder): return builder.EndObject() + +def MeanOptionsStart(builder): + builder.StartObject(1) + + +def MeanOptionsAddKeepDims(builder, keepDims): + builder.PrependBoolSlot(0, keepDims, 0) + + +def MeanOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/Model.py b/tools/tflitefile_tool/tflite/Model.py index 9b24555..dda9afa 100644 --- a/tools/tflitefile_tool/tflite/Model.py +++ b/tools/tflitefile_tool/tflite/Model.py @@ -4,6 +4,7 @@ import flatbuffers + class Model(object): __slots__ = ['_tab'] @@ -92,13 +93,46 @@ class Model(object): return self._tab.VectorLen(o) return 0 -def ModelStart(builder): builder.StartObject(5) -def ModelAddVersion(builder, version): builder.PrependUint32Slot(0, version, 0) -def ModelAddOperatorCodes(builder, operatorCodes): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(operatorCodes), 0) -def ModelStartOperatorCodesVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def ModelAddSubgraphs(builder, subgraphs): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(subgraphs), 0) -def ModelStartSubgraphsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def ModelAddDescription(builder, description): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(description), 0) -def ModelAddBuffers(builder, buffers): builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(buffers), 0) -def ModelStartBuffersVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def ModelEnd(builder): return builder.EndObject() + +def ModelStart(builder): + builder.StartObject(5) + + +def ModelAddVersion(builder, version): + builder.PrependUint32Slot(0, version, 0) + + +def ModelAddOperatorCodes(builder, operatorCodes): + builder.PrependUOffsetTRelativeSlot( + 1, flatbuffers.number_types.UOffsetTFlags.py_type(operatorCodes), 0) + + +def ModelStartOperatorCodesVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def ModelAddSubgraphs(builder, subgraphs): + builder.PrependUOffsetTRelativeSlot( + 2, flatbuffers.number_types.UOffsetTFlags.py_type(subgraphs), 0) + + +def ModelStartSubgraphsVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def ModelAddDescription(builder, description): + builder.PrependUOffsetTRelativeSlot( + 3, flatbuffers.number_types.UOffsetTFlags.py_type(description), 0) + + +def ModelAddBuffers(builder, buffers): + builder.PrependUOffsetTRelativeSlot( + 4, flatbuffers.number_types.UOffsetTFlags.py_type(buffers), 0) + + +def ModelStartBuffersVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def ModelEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/MulOptions.py b/tools/tflitefile_tool/tflite/MulOptions.py index 55b9506..e15c4d6 100644 --- a/tools/tflitefile_tool/tflite/MulOptions.py +++ b/tools/tflitefile_tool/tflite/MulOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class MulOptions(object): __slots__ = ['_tab'] @@ -25,6 +26,14 @@ class MulOptions(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def MulOptionsStart(builder): builder.StartObject(1) -def MulOptionsAddFusedActivationFunction(builder, fusedActivationFunction): builder.PrependInt8Slot(0, fusedActivationFunction, 0) -def MulOptionsEnd(builder): return builder.EndObject() + +def MulOptionsStart(builder): + builder.StartObject(1) + + +def MulOptionsAddFusedActivationFunction(builder, fusedActivationFunction): + builder.PrependInt8Slot(0, fusedActivationFunction, 0) + + +def MulOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/Operator.py b/tools/tflitefile_tool/tflite/Operator.py index 881a6ed..889d484 100644 --- a/tools/tflitefile_tool/tflite/Operator.py +++ b/tools/tflitefile_tool/tflite/Operator.py @@ -4,6 +4,7 @@ import flatbuffers + class Operator(object): __slots__ = ['_tab'] @@ -30,7 +31,9 @@ class Operator(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) if o != 0: a = self._tab.Vector(o) - return self._tab.Get(flatbuffers.number_types.Int32Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return self._tab.Get( + flatbuffers.number_types.Int32Flags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) return 0 # Operator @@ -52,7 +55,9 @@ class Operator(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) if o != 0: a = self._tab.Vector(o) - return self._tab.Get(flatbuffers.number_types.Int32Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return self._tab.Get( + flatbuffers.number_types.Int32Flags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) return 0 # Operator @@ -91,7 +96,9 @@ class Operator(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) if o != 0: a = self._tab.Vector(o) - return self._tab.Get(flatbuffers.number_types.Uint8Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 1)) + return self._tab.Get( + flatbuffers.number_types.Uint8Flags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 1)) return 0 # Operator @@ -115,15 +122,54 @@ class Operator(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def OperatorStart(builder): builder.StartObject(7) -def OperatorAddOpcodeIndex(builder, opcodeIndex): builder.PrependUint32Slot(0, opcodeIndex, 0) -def OperatorAddInputs(builder, inputs): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(inputs), 0) -def OperatorStartInputsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def OperatorAddOutputs(builder, outputs): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(outputs), 0) -def OperatorStartOutputsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def OperatorAddBuiltinOptionsType(builder, builtinOptionsType): builder.PrependUint8Slot(3, builtinOptionsType, 0) -def OperatorAddBuiltinOptions(builder, builtinOptions): builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(builtinOptions), 0) -def OperatorAddCustomOptions(builder, customOptions): builder.PrependUOffsetTRelativeSlot(5, flatbuffers.number_types.UOffsetTFlags.py_type(customOptions), 0) -def OperatorStartCustomOptionsVector(builder, numElems): return builder.StartVector(1, numElems, 1) -def OperatorAddCustomOptionsFormat(builder, customOptionsFormat): builder.PrependInt8Slot(6, customOptionsFormat, 0) -def OperatorEnd(builder): return builder.EndObject() + +def OperatorStart(builder): + builder.StartObject(7) + + +def OperatorAddOpcodeIndex(builder, opcodeIndex): + builder.PrependUint32Slot(0, opcodeIndex, 0) + + +def OperatorAddInputs(builder, inputs): + builder.PrependUOffsetTRelativeSlot( + 1, flatbuffers.number_types.UOffsetTFlags.py_type(inputs), 0) + + +def OperatorStartInputsVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def OperatorAddOutputs(builder, outputs): + builder.PrependUOffsetTRelativeSlot( + 2, flatbuffers.number_types.UOffsetTFlags.py_type(outputs), 0) + + +def OperatorStartOutputsVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def OperatorAddBuiltinOptionsType(builder, builtinOptionsType): + builder.PrependUint8Slot(3, builtinOptionsType, 0) + + +def OperatorAddBuiltinOptions(builder, builtinOptions): + builder.PrependUOffsetTRelativeSlot( + 4, flatbuffers.number_types.UOffsetTFlags.py_type(builtinOptions), 0) + + +def OperatorAddCustomOptions(builder, customOptions): + builder.PrependUOffsetTRelativeSlot( + 5, flatbuffers.number_types.UOffsetTFlags.py_type(customOptions), 0) + + +def OperatorStartCustomOptionsVector(builder, numElems): + return builder.StartVector(1, numElems, 1) + + +def OperatorAddCustomOptionsFormat(builder, customOptionsFormat): + builder.PrependInt8Slot(6, customOptionsFormat, 0) + + +def OperatorEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/OperatorCode.py b/tools/tflitefile_tool/tflite/OperatorCode.py index 68ddc58..a9bbf3c 100644 --- a/tools/tflitefile_tool/tflite/OperatorCode.py +++ b/tools/tflitefile_tool/tflite/OperatorCode.py @@ -4,6 +4,7 @@ import flatbuffers + class OperatorCode(object): __slots__ = ['_tab'] @@ -32,7 +33,19 @@ class OperatorCode(object): return self._tab.String(o + self._tab.Pos) return bytes() -def OperatorCodeStart(builder): builder.StartObject(2) -def OperatorCodeAddBuiltinCode(builder, builtinCode): builder.PrependInt8Slot(0, builtinCode, 0) -def OperatorCodeAddCustomCode(builder, customCode): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(customCode), 0) -def OperatorCodeEnd(builder): return builder.EndObject() + +def OperatorCodeStart(builder): + builder.StartObject(2) + + +def OperatorCodeAddBuiltinCode(builder, builtinCode): + builder.PrependInt8Slot(0, builtinCode, 0) + + +def OperatorCodeAddCustomCode(builder, customCode): + builder.PrependUOffsetTRelativeSlot( + 1, flatbuffers.number_types.UOffsetTFlags.py_type(customCode), 0) + + +def OperatorCodeEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/PadOptions.py b/tools/tflitefile_tool/tflite/PadOptions.py index d0833c6..4603944 100644 --- a/tools/tflitefile_tool/tflite/PadOptions.py +++ b/tools/tflitefile_tool/tflite/PadOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class PadOptions(object): __slots__ = ['_tab'] @@ -18,5 +19,10 @@ class PadOptions(object): def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) -def PadOptionsStart(builder): builder.StartObject(0) -def PadOptionsEnd(builder): return builder.EndObject() + +def PadOptionsStart(builder): + builder.StartObject(0) + + +def PadOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/Padding.py b/tools/tflitefile_tool/tflite/Padding.py index 6027f4b..b8b908c 100644 --- a/tools/tflitefile_tool/tflite/Padding.py +++ b/tools/tflitefile_tool/tflite/Padding.py @@ -2,7 +2,7 @@ # namespace: tflite + class Padding(object): SAME = 0 VALID = 1 - diff --git a/tools/tflitefile_tool/tflite/Pool2DOptions.py b/tools/tflitefile_tool/tflite/Pool2DOptions.py index b8b9f17..26e46f2 100644 --- a/tools/tflitefile_tool/tflite/Pool2DOptions.py +++ b/tools/tflitefile_tool/tflite/Pool2DOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class Pool2DOptions(object): __slots__ = ['_tab'] @@ -60,11 +61,34 @@ class Pool2DOptions(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def Pool2DOptionsStart(builder): builder.StartObject(6) -def Pool2DOptionsAddPadding(builder, padding): builder.PrependInt8Slot(0, padding, 0) -def Pool2DOptionsAddStrideW(builder, strideW): builder.PrependInt32Slot(1, strideW, 0) -def Pool2DOptionsAddStrideH(builder, strideH): builder.PrependInt32Slot(2, strideH, 0) -def Pool2DOptionsAddFilterWidth(builder, filterWidth): builder.PrependInt32Slot(3, filterWidth, 0) -def Pool2DOptionsAddFilterHeight(builder, filterHeight): builder.PrependInt32Slot(4, filterHeight, 0) -def Pool2DOptionsAddFusedActivationFunction(builder, fusedActivationFunction): builder.PrependInt8Slot(5, fusedActivationFunction, 0) -def Pool2DOptionsEnd(builder): return builder.EndObject() + +def Pool2DOptionsStart(builder): + builder.StartObject(6) + + +def Pool2DOptionsAddPadding(builder, padding): + builder.PrependInt8Slot(0, padding, 0) + + +def Pool2DOptionsAddStrideW(builder, strideW): + builder.PrependInt32Slot(1, strideW, 0) + + +def Pool2DOptionsAddStrideH(builder, strideH): + builder.PrependInt32Slot(2, strideH, 0) + + +def Pool2DOptionsAddFilterWidth(builder, filterWidth): + builder.PrependInt32Slot(3, filterWidth, 0) + + +def Pool2DOptionsAddFilterHeight(builder, filterHeight): + builder.PrependInt32Slot(4, filterHeight, 0) + + +def Pool2DOptionsAddFusedActivationFunction(builder, fusedActivationFunction): + builder.PrependInt8Slot(5, fusedActivationFunction, 0) + + +def Pool2DOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/QuantizationParameters.py b/tools/tflitefile_tool/tflite/QuantizationParameters.py index a7e7efa..7d5e530 100644 --- a/tools/tflitefile_tool/tflite/QuantizationParameters.py +++ b/tools/tflitefile_tool/tflite/QuantizationParameters.py @@ -4,6 +4,7 @@ import flatbuffers + class QuantizationParameters(object): __slots__ = ['_tab'] @@ -23,7 +24,9 @@ class QuantizationParameters(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) if o != 0: a = self._tab.Vector(o) - return self._tab.Get(flatbuffers.number_types.Float32Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return self._tab.Get( + flatbuffers.number_types.Float32Flags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) return 0 # QuantizationParameters @@ -45,7 +48,9 @@ class QuantizationParameters(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) if o != 0: a = self._tab.Vector(o) - return self._tab.Get(flatbuffers.number_types.Float32Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return self._tab.Get( + flatbuffers.number_types.Float32Flags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) return 0 # QuantizationParameters @@ -67,7 +72,9 @@ class QuantizationParameters(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) if o != 0: a = self._tab.Vector(o) - return self._tab.Get(flatbuffers.number_types.Float32Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return self._tab.Get( + flatbuffers.number_types.Float32Flags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) return 0 # QuantizationParameters @@ -89,7 +96,9 @@ class QuantizationParameters(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) if o != 0: a = self._tab.Vector(o) - return self._tab.Get(flatbuffers.number_types.Int64Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 8)) + return self._tab.Get( + flatbuffers.number_types.Int64Flags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 8)) return 0 # QuantizationParameters @@ -106,13 +115,46 @@ class QuantizationParameters(object): return self._tab.VectorLen(o) return 0 -def QuantizationParametersStart(builder): builder.StartObject(4) -def QuantizationParametersAddMin(builder, min): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(min), 0) -def QuantizationParametersStartMinVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def QuantizationParametersAddMax(builder, max): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(max), 0) -def QuantizationParametersStartMaxVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def QuantizationParametersAddScale(builder, scale): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(scale), 0) -def QuantizationParametersStartScaleVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def QuantizationParametersAddZeroPoint(builder, zeroPoint): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(zeroPoint), 0) -def QuantizationParametersStartZeroPointVector(builder, numElems): return builder.StartVector(8, numElems, 8) -def QuantizationParametersEnd(builder): return builder.EndObject() + +def QuantizationParametersStart(builder): + builder.StartObject(4) + + +def QuantizationParametersAddMin(builder, min): + builder.PrependUOffsetTRelativeSlot( + 0, flatbuffers.number_types.UOffsetTFlags.py_type(min), 0) + + +def QuantizationParametersStartMinVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def QuantizationParametersAddMax(builder, max): + builder.PrependUOffsetTRelativeSlot( + 1, flatbuffers.number_types.UOffsetTFlags.py_type(max), 0) + + +def QuantizationParametersStartMaxVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def QuantizationParametersAddScale(builder, scale): + builder.PrependUOffsetTRelativeSlot( + 2, flatbuffers.number_types.UOffsetTFlags.py_type(scale), 0) + + +def QuantizationParametersStartScaleVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def QuantizationParametersAddZeroPoint(builder, zeroPoint): + builder.PrependUOffsetTRelativeSlot( + 3, flatbuffers.number_types.UOffsetTFlags.py_type(zeroPoint), 0) + + +def QuantizationParametersStartZeroPointVector(builder, numElems): + return builder.StartVector(8, numElems, 8) + + +def QuantizationParametersEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/RNNOptions.py b/tools/tflitefile_tool/tflite/RNNOptions.py index 3cfdb6a..508b9c8 100644 --- a/tools/tflitefile_tool/tflite/RNNOptions.py +++ b/tools/tflitefile_tool/tflite/RNNOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class RNNOptions(object): __slots__ = ['_tab'] @@ -25,6 +26,14 @@ class RNNOptions(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def RNNOptionsStart(builder): builder.StartObject(1) -def RNNOptionsAddFusedActivationFunction(builder, fusedActivationFunction): builder.PrependInt8Slot(0, fusedActivationFunction, 0) -def RNNOptionsEnd(builder): return builder.EndObject() + +def RNNOptionsStart(builder): + builder.StartObject(1) + + +def RNNOptionsAddFusedActivationFunction(builder, fusedActivationFunction): + builder.PrependInt8Slot(0, fusedActivationFunction, 0) + + +def RNNOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/ReshapeOptions.py b/tools/tflitefile_tool/tflite/ReshapeOptions.py index 157d45d..b6b2b35 100644 --- a/tools/tflitefile_tool/tflite/ReshapeOptions.py +++ b/tools/tflitefile_tool/tflite/ReshapeOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class ReshapeOptions(object): __slots__ = ['_tab'] @@ -23,7 +24,9 @@ class ReshapeOptions(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) if o != 0: a = self._tab.Vector(o) - return self._tab.Get(flatbuffers.number_types.Int32Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return self._tab.Get( + flatbuffers.number_types.Int32Flags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) return 0 # ReshapeOptions @@ -40,7 +43,19 @@ class ReshapeOptions(object): return self._tab.VectorLen(o) return 0 -def ReshapeOptionsStart(builder): builder.StartObject(1) -def ReshapeOptionsAddNewShape(builder, newShape): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(newShape), 0) -def ReshapeOptionsStartNewShapeVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def ReshapeOptionsEnd(builder): return builder.EndObject() + +def ReshapeOptionsStart(builder): + builder.StartObject(1) + + +def ReshapeOptionsAddNewShape(builder, newShape): + builder.PrependUOffsetTRelativeSlot( + 0, flatbuffers.number_types.UOffsetTFlags.py_type(newShape), 0) + + +def ReshapeOptionsStartNewShapeVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def ReshapeOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/ResizeBilinearOptions.py b/tools/tflitefile_tool/tflite/ResizeBilinearOptions.py index 8d81b1d..66512bb 100644 --- a/tools/tflitefile_tool/tflite/ResizeBilinearOptions.py +++ b/tools/tflitefile_tool/tflite/ResizeBilinearOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class ResizeBilinearOptions(object): __slots__ = ['_tab'] @@ -25,6 +26,14 @@ class ResizeBilinearOptions(object): return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos) return 0 -def ResizeBilinearOptionsStart(builder): builder.StartObject(3) -def ResizeBilinearOptionsAddAlignCorners(builder, alignCorners): builder.PrependBoolSlot(2, alignCorners, 0) -def ResizeBilinearOptionsEnd(builder): return builder.EndObject() + +def ResizeBilinearOptionsStart(builder): + builder.StartObject(3) + + +def ResizeBilinearOptionsAddAlignCorners(builder, alignCorners): + builder.PrependBoolSlot(2, alignCorners, 0) + + +def ResizeBilinearOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/SVDFOptions.py b/tools/tflitefile_tool/tflite/SVDFOptions.py index 6f391db..1e65dff 100644 --- a/tools/tflitefile_tool/tflite/SVDFOptions.py +++ b/tools/tflitefile_tool/tflite/SVDFOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class SVDFOptions(object): __slots__ = ['_tab'] @@ -32,7 +33,18 @@ class SVDFOptions(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def SVDFOptionsStart(builder): builder.StartObject(2) -def SVDFOptionsAddRank(builder, rank): builder.PrependInt32Slot(0, rank, 0) -def SVDFOptionsAddFusedActivationFunction(builder, fusedActivationFunction): builder.PrependInt8Slot(1, fusedActivationFunction, 0) -def SVDFOptionsEnd(builder): return builder.EndObject() + +def SVDFOptionsStart(builder): + builder.StartObject(2) + + +def SVDFOptionsAddRank(builder, rank): + builder.PrependInt32Slot(0, rank, 0) + + +def SVDFOptionsAddFusedActivationFunction(builder, fusedActivationFunction): + builder.PrependInt8Slot(1, fusedActivationFunction, 0) + + +def SVDFOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/SequenceRNNOptions.py b/tools/tflitefile_tool/tflite/SequenceRNNOptions.py index 87b0961..bee7a0f 100644 --- a/tools/tflitefile_tool/tflite/SequenceRNNOptions.py +++ b/tools/tflitefile_tool/tflite/SequenceRNNOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class SequenceRNNOptions(object): __slots__ = ['_tab'] @@ -32,7 +33,18 @@ class SequenceRNNOptions(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def SequenceRNNOptionsStart(builder): builder.StartObject(2) -def SequenceRNNOptionsAddTimeMajor(builder, timeMajor): builder.PrependBoolSlot(0, timeMajor, 0) -def SequenceRNNOptionsAddFusedActivationFunction(builder, fusedActivationFunction): builder.PrependInt8Slot(1, fusedActivationFunction, 0) -def SequenceRNNOptionsEnd(builder): return builder.EndObject() + +def SequenceRNNOptionsStart(builder): + builder.StartObject(2) + + +def SequenceRNNOptionsAddTimeMajor(builder, timeMajor): + builder.PrependBoolSlot(0, timeMajor, 0) + + +def SequenceRNNOptionsAddFusedActivationFunction(builder, fusedActivationFunction): + builder.PrependInt8Slot(1, fusedActivationFunction, 0) + + +def SequenceRNNOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/SkipGramOptions.py b/tools/tflitefile_tool/tflite/SkipGramOptions.py index 27b2c40..50738b9 100644 --- a/tools/tflitefile_tool/tflite/SkipGramOptions.py +++ b/tools/tflitefile_tool/tflite/SkipGramOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class SkipGramOptions(object): __slots__ = ['_tab'] @@ -39,8 +40,22 @@ class SkipGramOptions(object): return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos) return 0 -def SkipGramOptionsStart(builder): builder.StartObject(3) -def SkipGramOptionsAddNgramSize(builder, ngramSize): builder.PrependInt32Slot(0, ngramSize, 0) -def SkipGramOptionsAddMaxSkipSize(builder, maxSkipSize): builder.PrependInt32Slot(1, maxSkipSize, 0) -def SkipGramOptionsAddIncludeAllNgrams(builder, includeAllNgrams): builder.PrependBoolSlot(2, includeAllNgrams, 0) -def SkipGramOptionsEnd(builder): return builder.EndObject() + +def SkipGramOptionsStart(builder): + builder.StartObject(3) + + +def SkipGramOptionsAddNgramSize(builder, ngramSize): + builder.PrependInt32Slot(0, ngramSize, 0) + + +def SkipGramOptionsAddMaxSkipSize(builder, maxSkipSize): + builder.PrependInt32Slot(1, maxSkipSize, 0) + + +def SkipGramOptionsAddIncludeAllNgrams(builder, includeAllNgrams): + builder.PrependBoolSlot(2, includeAllNgrams, 0) + + +def SkipGramOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/SoftmaxOptions.py b/tools/tflitefile_tool/tflite/SoftmaxOptions.py index a716853..05571f2 100644 --- a/tools/tflitefile_tool/tflite/SoftmaxOptions.py +++ b/tools/tflitefile_tool/tflite/SoftmaxOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class SoftmaxOptions(object): __slots__ = ['_tab'] @@ -25,6 +26,14 @@ class SoftmaxOptions(object): return self._tab.Get(flatbuffers.number_types.Float32Flags, o + self._tab.Pos) return 0.0 -def SoftmaxOptionsStart(builder): builder.StartObject(1) -def SoftmaxOptionsAddBeta(builder, beta): builder.PrependFloat32Slot(0, beta, 0.0) -def SoftmaxOptionsEnd(builder): return builder.EndObject() + +def SoftmaxOptionsStart(builder): + builder.StartObject(1) + + +def SoftmaxOptionsAddBeta(builder, beta): + builder.PrependFloat32Slot(0, beta, 0.0) + + +def SoftmaxOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/SpaceToBatchNDOptions.py b/tools/tflitefile_tool/tflite/SpaceToBatchNDOptions.py index b61ef96..ee31e0d 100644 --- a/tools/tflitefile_tool/tflite/SpaceToBatchNDOptions.py +++ b/tools/tflitefile_tool/tflite/SpaceToBatchNDOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class SpaceToBatchNDOptions(object): __slots__ = ['_tab'] @@ -18,5 +19,10 @@ class SpaceToBatchNDOptions(object): def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) -def SpaceToBatchNDOptionsStart(builder): builder.StartObject(0) -def SpaceToBatchNDOptionsEnd(builder): return builder.EndObject() + +def SpaceToBatchNDOptionsStart(builder): + builder.StartObject(0) + + +def SpaceToBatchNDOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/SpaceToDepthOptions.py b/tools/tflitefile_tool/tflite/SpaceToDepthOptions.py index d571174..277fa1a 100644 --- a/tools/tflitefile_tool/tflite/SpaceToDepthOptions.py +++ b/tools/tflitefile_tool/tflite/SpaceToDepthOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class SpaceToDepthOptions(object): __slots__ = ['_tab'] @@ -25,6 +26,14 @@ class SpaceToDepthOptions(object): return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) return 0 -def SpaceToDepthOptionsStart(builder): builder.StartObject(1) -def SpaceToDepthOptionsAddBlockSize(builder, blockSize): builder.PrependInt32Slot(0, blockSize, 0) -def SpaceToDepthOptionsEnd(builder): return builder.EndObject() + +def SpaceToDepthOptionsStart(builder): + builder.StartObject(1) + + +def SpaceToDepthOptionsAddBlockSize(builder, blockSize): + builder.PrependInt32Slot(0, blockSize, 0) + + +def SpaceToDepthOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/SplitOptions.py b/tools/tflitefile_tool/tflite/SplitOptions.py index 3207525..a591e2e 100644 --- a/tools/tflitefile_tool/tflite/SplitOptions.py +++ b/tools/tflitefile_tool/tflite/SplitOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class SplitOptions(object): __slots__ = ['_tab'] @@ -25,6 +26,14 @@ class SplitOptions(object): return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) return 0 -def SplitOptionsStart(builder): builder.StartObject(1) -def SplitOptionsAddNumSplits(builder, numSplits): builder.PrependInt32Slot(0, numSplits, 0) -def SplitOptionsEnd(builder): return builder.EndObject() + +def SplitOptionsStart(builder): + builder.StartObject(1) + + +def SplitOptionsAddNumSplits(builder, numSplits): + builder.PrependInt32Slot(0, numSplits, 0) + + +def SplitOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/SqueezeOptions.py b/tools/tflitefile_tool/tflite/SqueezeOptions.py index 25b294d..6881c11 100644 --- a/tools/tflitefile_tool/tflite/SqueezeOptions.py +++ b/tools/tflitefile_tool/tflite/SqueezeOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class SqueezeOptions(object): __slots__ = ['_tab'] @@ -23,7 +24,9 @@ class SqueezeOptions(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) if o != 0: a = self._tab.Vector(o) - return self._tab.Get(flatbuffers.number_types.Int32Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return self._tab.Get( + flatbuffers.number_types.Int32Flags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) return 0 # SqueezeOptions @@ -40,7 +43,19 @@ class SqueezeOptions(object): return self._tab.VectorLen(o) return 0 -def SqueezeOptionsStart(builder): builder.StartObject(1) -def SqueezeOptionsAddSqueezeDims(builder, squeezeDims): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(squeezeDims), 0) -def SqueezeOptionsStartSqueezeDimsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def SqueezeOptionsEnd(builder): return builder.EndObject() + +def SqueezeOptionsStart(builder): + builder.StartObject(1) + + +def SqueezeOptionsAddSqueezeDims(builder, squeezeDims): + builder.PrependUOffsetTRelativeSlot( + 0, flatbuffers.number_types.UOffsetTFlags.py_type(squeezeDims), 0) + + +def SqueezeOptionsStartSqueezeDimsVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def SqueezeOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/StridedSliceOptions.py b/tools/tflitefile_tool/tflite/StridedSliceOptions.py index 3bbb36b..99db0da 100644 --- a/tools/tflitefile_tool/tflite/StridedSliceOptions.py +++ b/tools/tflitefile_tool/tflite/StridedSliceOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class StridedSliceOptions(object): __slots__ = ['_tab'] @@ -53,10 +54,30 @@ class StridedSliceOptions(object): return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) return 0 -def StridedSliceOptionsStart(builder): builder.StartObject(5) -def StridedSliceOptionsAddBeginMask(builder, beginMask): builder.PrependInt32Slot(0, beginMask, 0) -def StridedSliceOptionsAddEndMask(builder, endMask): builder.PrependInt32Slot(1, endMask, 0) -def StridedSliceOptionsAddEllipsisMask(builder, ellipsisMask): builder.PrependInt32Slot(2, ellipsisMask, 0) -def StridedSliceOptionsAddNewAxisMask(builder, newAxisMask): builder.PrependInt32Slot(3, newAxisMask, 0) -def StridedSliceOptionsAddShrinkAxisMask(builder, shrinkAxisMask): builder.PrependInt32Slot(4, shrinkAxisMask, 0) -def StridedSliceOptionsEnd(builder): return builder.EndObject() + +def StridedSliceOptionsStart(builder): + builder.StartObject(5) + + +def StridedSliceOptionsAddBeginMask(builder, beginMask): + builder.PrependInt32Slot(0, beginMask, 0) + + +def StridedSliceOptionsAddEndMask(builder, endMask): + builder.PrependInt32Slot(1, endMask, 0) + + +def StridedSliceOptionsAddEllipsisMask(builder, ellipsisMask): + builder.PrependInt32Slot(2, ellipsisMask, 0) + + +def StridedSliceOptionsAddNewAxisMask(builder, newAxisMask): + builder.PrependInt32Slot(3, newAxisMask, 0) + + +def StridedSliceOptionsAddShrinkAxisMask(builder, shrinkAxisMask): + builder.PrependInt32Slot(4, shrinkAxisMask, 0) + + +def StridedSliceOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/SubGraph.py b/tools/tflitefile_tool/tflite/SubGraph.py index 0c04cb3..3e568e1 100644 --- a/tools/tflitefile_tool/tflite/SubGraph.py +++ b/tools/tflitefile_tool/tflite/SubGraph.py @@ -4,6 +4,7 @@ import flatbuffers + class SubGraph(object): __slots__ = ['_tab'] @@ -43,7 +44,9 @@ class SubGraph(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) if o != 0: a = self._tab.Vector(o) - return self._tab.Get(flatbuffers.number_types.Int32Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return self._tab.Get( + flatbuffers.number_types.Int32Flags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) return 0 # SubGraph @@ -65,7 +68,9 @@ class SubGraph(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) if o != 0: a = self._tab.Vector(o) - return self._tab.Get(flatbuffers.number_types.Int32Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return self._tab.Get( + flatbuffers.number_types.Int32Flags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) return 0 # SubGraph @@ -109,14 +114,51 @@ class SubGraph(object): return self._tab.String(o + self._tab.Pos) return bytes() -def SubGraphStart(builder): builder.StartObject(5) -def SubGraphAddTensors(builder, tensors): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(tensors), 0) -def SubGraphStartTensorsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def SubGraphAddInputs(builder, inputs): builder.PrependUOffsetTRelativeSlot(1, flatbuffers.number_types.UOffsetTFlags.py_type(inputs), 0) -def SubGraphStartInputsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def SubGraphAddOutputs(builder, outputs): builder.PrependUOffsetTRelativeSlot(2, flatbuffers.number_types.UOffsetTFlags.py_type(outputs), 0) -def SubGraphStartOutputsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def SubGraphAddOperators(builder, operators): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(operators), 0) -def SubGraphStartOperatorsVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def SubGraphAddName(builder, name): builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) -def SubGraphEnd(builder): return builder.EndObject() + +def SubGraphStart(builder): + builder.StartObject(5) + + +def SubGraphAddTensors(builder, tensors): + builder.PrependUOffsetTRelativeSlot( + 0, flatbuffers.number_types.UOffsetTFlags.py_type(tensors), 0) + + +def SubGraphStartTensorsVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def SubGraphAddInputs(builder, inputs): + builder.PrependUOffsetTRelativeSlot( + 1, flatbuffers.number_types.UOffsetTFlags.py_type(inputs), 0) + + +def SubGraphStartInputsVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def SubGraphAddOutputs(builder, outputs): + builder.PrependUOffsetTRelativeSlot( + 2, flatbuffers.number_types.UOffsetTFlags.py_type(outputs), 0) + + +def SubGraphStartOutputsVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def SubGraphAddOperators(builder, operators): + builder.PrependUOffsetTRelativeSlot( + 3, flatbuffers.number_types.UOffsetTFlags.py_type(operators), 0) + + +def SubGraphStartOperatorsVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def SubGraphAddName(builder, name): + builder.PrependUOffsetTRelativeSlot( + 4, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + + +def SubGraphEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/SubOptions.py b/tools/tflitefile_tool/tflite/SubOptions.py index eccd7ab..29b3dcb 100644 --- a/tools/tflitefile_tool/tflite/SubOptions.py +++ b/tools/tflitefile_tool/tflite/SubOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class SubOptions(object): __slots__ = ['_tab'] @@ -25,6 +26,14 @@ class SubOptions(object): return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) return 0 -def SubOptionsStart(builder): builder.StartObject(1) -def SubOptionsAddFusedActivationFunction(builder, fusedActivationFunction): builder.PrependInt8Slot(0, fusedActivationFunction, 0) -def SubOptionsEnd(builder): return builder.EndObject() + +def SubOptionsStart(builder): + builder.StartObject(1) + + +def SubOptionsAddFusedActivationFunction(builder, fusedActivationFunction): + builder.PrependInt8Slot(0, fusedActivationFunction, 0) + + +def SubOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/Tensor.py b/tools/tflitefile_tool/tflite/Tensor.py index f913e78..730e42f 100644 --- a/tools/tflitefile_tool/tflite/Tensor.py +++ b/tools/tflitefile_tool/tflite/Tensor.py @@ -4,6 +4,7 @@ import flatbuffers + class Tensor(object): __slots__ = ['_tab'] @@ -23,7 +24,9 @@ class Tensor(object): o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) if o != 0: a = self._tab.Vector(o) - return self._tab.Get(flatbuffers.number_types.Int32Flags, a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return self._tab.Get( + flatbuffers.number_types.Int32Flags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) return 0 # Tensor @@ -72,11 +75,37 @@ class Tensor(object): return obj return None -def TensorStart(builder): builder.StartObject(5) -def TensorAddShape(builder, shape): builder.PrependUOffsetTRelativeSlot(0, flatbuffers.number_types.UOffsetTFlags.py_type(shape), 0) -def TensorStartShapeVector(builder, numElems): return builder.StartVector(4, numElems, 4) -def TensorAddType(builder, type): builder.PrependInt8Slot(1, type, 0) -def TensorAddBuffer(builder, buffer): builder.PrependUint32Slot(2, buffer, 0) -def TensorAddName(builder, name): builder.PrependUOffsetTRelativeSlot(3, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) -def TensorAddQuantization(builder, quantization): builder.PrependUOffsetTRelativeSlot(4, flatbuffers.number_types.UOffsetTFlags.py_type(quantization), 0) -def TensorEnd(builder): return builder.EndObject() + +def TensorStart(builder): + builder.StartObject(5) + + +def TensorAddShape(builder, shape): + builder.PrependUOffsetTRelativeSlot( + 0, flatbuffers.number_types.UOffsetTFlags.py_type(shape), 0) + + +def TensorStartShapeVector(builder, numElems): + return builder.StartVector(4, numElems, 4) + + +def TensorAddType(builder, type): + builder.PrependInt8Slot(1, type, 0) + + +def TensorAddBuffer(builder, buffer): + builder.PrependUint32Slot(2, buffer, 0) + + +def TensorAddName(builder, name): + builder.PrependUOffsetTRelativeSlot( + 3, flatbuffers.number_types.UOffsetTFlags.py_type(name), 0) + + +def TensorAddQuantization(builder, quantization): + builder.PrependUOffsetTRelativeSlot( + 4, flatbuffers.number_types.UOffsetTFlags.py_type(quantization), 0) + + +def TensorEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/TensorType.py b/tools/tflitefile_tool/tflite/TensorType.py index ef1ecfe..e0490d0 100644 --- a/tools/tflitefile_tool/tflite/TensorType.py +++ b/tools/tflitefile_tool/tflite/TensorType.py @@ -2,6 +2,7 @@ # namespace: tflite + class TensorType(object): FLOAT32 = 0 FLOAT16 = 1 @@ -9,4 +10,3 @@ class TensorType(object): UINT8 = 3 INT64 = 4 STRING = 5 - diff --git a/tools/tflitefile_tool/tflite/TopKV2Options.py b/tools/tflitefile_tool/tflite/TopKV2Options.py index ccd5103..0048989 100644 --- a/tools/tflitefile_tool/tflite/TopKV2Options.py +++ b/tools/tflitefile_tool/tflite/TopKV2Options.py @@ -4,6 +4,7 @@ import flatbuffers + class TopKV2Options(object): __slots__ = ['_tab'] @@ -18,5 +19,10 @@ class TopKV2Options(object): def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) -def TopKV2OptionsStart(builder): builder.StartObject(0) -def TopKV2OptionsEnd(builder): return builder.EndObject() + +def TopKV2OptionsStart(builder): + builder.StartObject(0) + + +def TopKV2OptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/TransposeOptions.py b/tools/tflitefile_tool/tflite/TransposeOptions.py index 42c596d..b796686 100644 --- a/tools/tflitefile_tool/tflite/TransposeOptions.py +++ b/tools/tflitefile_tool/tflite/TransposeOptions.py @@ -4,6 +4,7 @@ import flatbuffers + class TransposeOptions(object): __slots__ = ['_tab'] @@ -18,5 +19,10 @@ class TransposeOptions(object): def Init(self, buf, pos): self._tab = flatbuffers.table.Table(buf, pos) -def TransposeOptionsStart(builder): builder.StartObject(0) -def TransposeOptionsEnd(builder): return builder.EndObject() + +def TransposeOptionsStart(builder): + builder.StartObject(0) + + +def TransposeOptionsEnd(builder): + return builder.EndObject()