diff options
Diffstat (limited to 'tools/tflitefile_tool')
86 files changed, 5308 insertions, 0 deletions
diff --git a/tools/tflitefile_tool/README.md b/tools/tflitefile_tool/README.md new file mode 100644 index 000000000..e88669843 --- /dev/null +++ b/tools/tflitefile_tool/README.md @@ -0,0 +1,81 @@ +## Model parser + +### Purpose + +This tool print operators, tensors, and buffers information in tflite model file (`.tflite`) + +### How to use + +``` +./model_parser.py <model file> +``` + +### Example + +``` +$ ./tools/tflitefile_tool/model_parser.py /home/nnfw/convolution_test.tflite + +[Main model] + +Main model input tensors: [0] +Main model output tensors: [1] +Operators list + +Operator 0: CONV_2D + Input Tensors[0 3 2] + Output Tensors[1] + + +Tensor-Buffer mapping & shape + +Tensor 0 : buffer 3 | Empty | FLOAT32 | Shape [1, 299, 299, 3] (Mul) +Tensor 1 : buffer 4 | Empty | FLOAT32 | Shape [1, 149, 149, 32] (conv) +Tensor 2 : buffer 1 | Filled | FLOAT32 | Shape [32] (conv/Conv2D_bias) +Tensor 3 : buffer 2 | Filled | FLOAT32 | Shape [32, 3, 3, 3] (conv/conv2d_params) + +$ +``` + +## Model generator from other model file + +### Purpose + +This tool makes small model file from base model file (such as inception v3) + +### How to use + +``` +./select_operator.py <base model file> <opcode list txt file> <output file name> +``` + +### Example + +``` +$ cat /home/nnfw/opcodelist.txt +107 108 109 110 111 112 113 114 115 116 117 118 119 120 + +$ ./tools/tflitefile_tool/select_operator.py /home/nnfw/inceptionv3_non_slim_2015.tflite \ +/home/nnfw/opcodelist.txt /home/nnfw/test.tflite + +Input tensor(s): [29] +Output tensor(s): [31] + +$ Product/out/bin/tflite_run /home/nfs/inception_test.tflite +nnapi error: unable to open library libneuralnetworks.so +input tensor indices = [29,] +Input image size is smaller than the size required by the model. Input will not be set. +output tensor indices = [31(max:567),] +Prepare takes 0.000516954 seconds +Invoke takes 0.719677 seconds + +$ +``` + +You can use range such as `107-120` in `opcodelist.txt` instead of using each operator index + +## Colaboration model parser and model generator + +1. Get imformation about base model using model parser +2. Select operators you want to make test model +3. Make text file including selected operators index +4. Generate test model file using model generator diff --git a/tools/tflitefile_tool/model_parser.py b/tools/tflitefile_tool/model_parser.py new file mode 100755 index 000000000..b8967d33f --- /dev/null +++ b/tools/tflitefile_tool/model_parser.py @@ -0,0 +1,110 @@ +#!/usr/bin/python +import os +import sys +import numpy + +sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tflite')) +flatbuffersPath = '../../externals/flatbuffers' +sys.path.append( + os.path.join(os.path.dirname(os.path.abspath(__file__)), flatbuffersPath + '/python')) + +import flatbuffers +import tflite.Model +import tflite.SubGraph +import argparse +from operator_parser import OperatorParser +from perf_predictor import PerfPredictor + + +class TFLiteModelFileParser(object): + def __init__(self, args): + # Read flatbuffer file descriptor using argument + self.tflite_file = args.input_file + + # Set print level (0 ~ 2) + # TODO: print information based on level + self.print_level = args.verbose + if (args.verbose > 2): + self.print_level = 2 + if (args.verbose < 0): + self.print_level = 0 + + # Set tensor index list to print information + # TODO: + # Print tensors in list only + # Print all tensors if argument used and not specified index number + if (args.tensor != None): + if (len(args.tensor) == 0): + self.print_all_tensor = True + else: + self.print_all_tensor = False + self.print_tensor_index = [] + + for tensor_index in args.tensor: + self.print_tensor_index.append(int(tensor_index)) + + # Set operator index list to print information + # TODO: + # Print operators in list only + # Print all operators if argument used and not specified index number + if (args.operator != None): + if (len(args.operator) == 0): + self.print_all_oeprator = True + else: + self.print_all_oeprator = False + self.print_operator_index = [] + + for operator_index in args.operator: + self.print_operator_index.append(int(operator_index)) + + def main(self): + # Generate Model: top structure of tflite model file + buf = self.tflite_file.read() + buf = bytearray(buf) + tf_model = tflite.Model.Model.GetRootAsModel(buf, 0) + + # Model file can have many models + # 1st subgraph is main model + model_name = "Main model" + for subgraph_index in range(tf_model.SubgraphsLength()): + tf_subgraph = tf_model.Subgraphs(subgraph_index) + if (subgraph_index != 0): + model_name = "Model #" + str(subgraph_index) + + print("[" + model_name + "]\n") + + # Model inputs & outputs + model_inputs = tf_subgraph.InputsAsNumpy() + model_outputs = tf_subgraph.OutputsAsNumpy() + + print(model_name + " input tensors: " + str(model_inputs)) + print(model_name + " output tensors: " + str(model_outputs)) + + # Parse Operators and print all of operators + op_parser = OperatorParser(tf_model, tf_subgraph, PerfPredictor()) + op_parser.Parse() + op_parser.PrintAll() + + +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( + '-v', + '--verbose', + action='count', + default=0, + help="set print level (0~2, default: 0)") + arg_parser.add_argument( + '-t', '--tensor', nargs='*', help="tensor ID to print information (default: all)") + arg_parser.add_argument( + '-o', + '--operator', + nargs='*', + help="operator ID to print information (default: all)") + args = arg_parser.parse_args() + + # Call main function + TFLiteModelFileParser(args).main() diff --git a/tools/tflitefile_tool/operation.py b/tools/tflitefile_tool/operation.py new file mode 100755 index 000000000..77fc5db9a --- /dev/null +++ b/tools/tflitefile_tool/operation.py @@ -0,0 +1,199 @@ +#!/usr/bin/python + +import tflite.Conv2DOptions +import tflite.Pool2DOptions +import tflite.BuiltinOptions +import tflite.Tensor +from tensor_wrapping import Tensor +import math +''' +NOTICE +- an internal class. do not import outside this file. +- REF: https://stackoverflow.com/questions/551038/private-implementation-class-in-python +''' + + +class _OperationComputeMethod(object): + ''' + NOTE: How to count operations of convolution(and also pooling)? + + If we know operations of output's one element, we can calculate total output's operations. + For example, consider output Shape[3,3] + [ e11 e12 e13 ] + [ e21 e22 e23 ] + [ e31 e32 e33 ] + If we know operations for calculation of e11, we can know total operations of output(e11, e12, ... e33) + by operations of e11 * 9(total number of elements) + + So we only need to know how to calculate operations of e11. + For this, just think how to conv operation to the output's element + If input_channel is 1, we can only think of kernel_size(kernel_w and kernel_h). + For example, consider input Shape[3,3] and kernel Shape[2,2] + [ i11 i12 i13 ] [ k11 k12 ] [ o11 o12 o13 ] + [ i21 i22 i23 ] * [ k21 k22 ] = [ o21 o22 o23 ] + [ i31 i32 i33 ] [ o31 o32 o33 ] + + Conv operation: for o11, i11 * k11 + i21 * k21 + i12 * k12 + i22 * k22 = o11 + On above conv operation, mul operations are done at 4 times(== kernel_w * kernel_h) + and add operations are dont at 3 times(== kernel_w * kernel_h - 1) + and also, bias will be done and it will be counted on add operations. + + Anyway, we can calculate total operations on this way. This can apply to the way of pooling. + ''' + + def ComputeOperationForConv2D(tf_operator, inputs, outputs): + assert ( + tf_operator.BuiltinOptionsType() == tflite.BuiltinOptions.BuiltinOptions() + .Conv2DOptions) + + # NOTE: Assume that conv2d operator always take 3 tensors as inputs + # and both width and height are the same. + # operator_inputs[]: [input_tensor, weight_tensor, bias_tensor] + # operator_outputs[]: [output_tensor] + # tflite's tensor shape: [N,H,W,C] + input_tensor = inputs[0].tf_tensor + weight_tensor = inputs[1].tf_tensor + output_tensor = outputs[0].tf_tensor + + # kernel_ops = (kernel_w * kernel_h * input_channel * 2(multiply and add)) + kernel_ops = ( + weight_tensor.Shape(2) * weight_tensor.Shape(1) * input_tensor.Shape(3)) + + # total ops + # = batch_size * output_channel * output_width * output_height * kernel_ops + total_ops = (output_tensor.Shape(0) * output_tensor.Shape(3) * + output_tensor.Shape(2) * output_tensor.Shape(1)) + + add_instr_num = (total_ops * (kernel_ops + 1)) # bias + mul_instr_num = (total_ops * (kernel_ops)) + nonlinear_instr_num = 0 + return (add_instr_num, mul_instr_num, nonlinear_instr_num) + + ''' + NOTE: Reference the comment 'NOTE' of ComputeOperationForConv2D + ''' + + def ComputeOperationForPooling(tf_operator, inputs, outputs): + assert ( + tf_operator.BuiltinOptionsType() == tflite.BuiltinOptions.BuiltinOptions() + .Pool2DOptions) + + input_tensor = inputs[0].tf_tensor + output_tensor = outputs[0].tf_tensor + + pool2d_options = tflite.Pool2DOptions.Pool2DOptions() + pool2d_options.Init(tf_operator.BuiltinOptions().Bytes, + tf_operator.BuiltinOptions().Pos) + + # kernel_ops = kernel_w * kernel_h + kernel_ops = (pool2d_options.FilterWidth() * pool2d_options.FilterHeight()) + + # total ops + # = batch_size * output_channel * output_width * output_height * + # kernel_ops(kernel_w * kernel_h) + total_ops = (output_tensor.Shape(0) * output_tensor.Shape(3) * + output_tensor.Shape(2) * output_tensor.Shape(1)) + + add_instr_num = (total_ops * kernel_ops - 1) + mul_instr_num = (total_ops * kernel_ops) + nonlinear_instr_num = 0 + return (add_instr_num, mul_instr_num, nonlinear_instr_num) + + def ComputeOperationForSoftmax(tf_operator, inputs, outputs): + assert ( + tf_operator.BuiltinOptionsType() == tflite.BuiltinOptions.BuiltinOptions() + .SoftmaxOptions) + + input_tensor = inputs[0].tf_tensor + + batch_size = input_tensor.Shape(0) + input_dim = input_tensor.Shape(1) + + # Softmax(x_i) = exp(x_i) / sum of exp(x) + add_instr_num = input_dim - 1 # sum of exp(x) + mul_instr_num = input_dim # / + nonlinear_instr_num = input_dim + input_dim # sum of exp(x) and exp(x_i) + return (add_instr_num, mul_instr_num, nonlinear_instr_num) + + def ComputeOperationForFullyConnected(tf_operator, inputs, outputs): + assert ( + tf_operator.BuiltinOptionsType() == tflite.BuiltinOptions.BuiltinOptions() + .FullyConnectedOptions) + + # NOTE: Assume that fully_connected operator always take 3 tensors as inputs + # and its X tensor's shape is [1, 1, 1, input_dim] with + # its output Y [1, output_dim] + input_tensor = inputs[0].tf_tensor + output_tensor = outputs[0].tf_tensor + + # ops_per_element + # = input_dim(multiplication) + input_dim-1(addition) + 1(bias) + # total_ops + # = ops_per_elem * output_dim + + add_instr_num = (input_tensor.Shape(3) * output_tensor.Shape(1)) + mul_instr_num = (input_tensor.Shape(3) * output_tensor.Shape(1)) + nonlinear_instr_num = 0 + return (add_instr_num, mul_instr_num, nonlinear_instr_num) + + def ComputeOperationForNothing(tf_operator, inputs, outputs): + add_instr_num = 0 + mul_instr_num = 0 + nonlinear_instr_num = 0 + return (add_instr_num, mul_instr_num, nonlinear_instr_num) + + def NYI_ComputeOperation(tf_operator, inputs, outputs): + pass + + operation_to_method_map = { + # Inceptionv3 + "CONV_2D": ComputeOperationForConv2D, + "AVERAGE_POOL_2D": ComputeOperationForPooling, + "MAX_POOL_2D": ComputeOperationForPooling, + "SOFTMAX": ComputeOperationForSoftmax, + "FULLY_CONNECTED": ComputeOperationForFullyConnected, + "CONCATENATION": ComputeOperationForNothing, + # ADAS + "TOPK_V2": NYI_ComputeOperation, + "SUB": NYI_ComputeOperation, + "STRIDED_SLICE": NYI_ComputeOperation, + "RESHAPE": NYI_ComputeOperation, + "GATHER": NYI_ComputeOperation, + "RESIZE_BILINEAR": NYI_ComputeOperation, + "CAST": NYI_ComputeOperation, + "ADD": NYI_ComputeOperation, + "MUL": NYI_ComputeOperation, + "DIV": NYI_ComputeOperation, + "CUSTOM(TensorFlowMax)": NYI_ComputeOperation, + "CUSTOM": NYI_ComputeOperation, + } + + +class Operation(object): + def __init__(self, tf_operator, operator_str, inputs, outputs): + self.tf_operator = tf_operator + self.operator_str = operator_str + self.inputs = inputs + self.outputs = outputs + self.add_instr_num = 0 + self.mul_instr_num = 0 + self.nonlinear_instr_num = 0 + self.can_compute = True + self.Compute() + + def Compute(self): + comp_map = _OperationComputeMethod().operation_to_method_map + if not self.operator_str in comp_map.keys(): + self.can_compute = False + return + + method = comp_map[self.operator_str] + if method.__name__ == _OperationComputeMethod().NYI_ComputeOperation.__name__: + self.can_compute = False + return + + self.add_instr_num, self.mul_instr_num, self.nonlinear_instr_num = method( + self.tf_operator, self.inputs, self.outputs) + + def TotalInstrNum(self): + return (self.add_instr_num + self.mul_instr_num + self.nonlinear_instr_num) diff --git a/tools/tflitefile_tool/operator_parser.py b/tools/tflitefile_tool/operator_parser.py new file mode 100755 index 000000000..9728d53b7 --- /dev/null +++ b/tools/tflitefile_tool/operator_parser.py @@ -0,0 +1,113 @@ +#!/usr/bin/python + +import tflite.Model +import tflite.SubGraph +import tflite.Operator +import tflite.OperatorCode +import tflite.BuiltinOperator +from operator_wrapping import Operator, EnumStrMaps +from tensor_wrapping import Tensor, SetTensorTypeStr +from operation import Operation + + +class OperatorParser(object): + def __init__(self, tf_model, tf_subgraph, perf_predictor=None): + self.tf_model = tf_model + self.tf_subgraph = tf_subgraph + self.perf_predictor = perf_predictor + self.operators_in_list = list() + self.operators_per_type = dict() + # Tensor type string table + SetTensorTypeStr() + + def Parse(self): + for operator_idx in range(self.tf_subgraph.OperatorsLength()): + tf_operator = self.tf_subgraph.Operators(operator_idx) + opcode_str = self.GetOpcodeStr(tf_operator) + input_tensors = self.GetInputTensors(tf_operator) + output_tensors = self.GetOutputTensors(tf_operator) + + op = Operator(operator_idx, tf_operator, input_tensors, output_tensors, + opcode_str) + self.AppendOperator(op) + + def GetOpcodeStr(self, tf_operator): + opcode_list_idx = tf_operator.OpcodeIndex() + opcode_id = self.tf_model.OperatorCodes(opcode_list_idx).BuiltinCode() + opcode_str = EnumStrMaps.BuiltinOpcode[opcode_id] + if opcode_id == 32: + # Custom operator + custom_operator = self.tf_model.OperatorCodes(tf_operator.OpcodeIndex()) + custom_op_name = custom_operator.CustomCode().decode('utf-8') + opcode_str = opcode_str + "(" + custom_op_name + ")" + return opcode_str + + def GetInputTensors(self, tf_operator): + operator_inputs = tf_operator.InputsAsNumpy() + return self.GetTensors(operator_inputs) + + def GetOutputTensors(self, tf_operator): + operator_outputs = tf_operator.OutputsAsNumpy() + return self.GetTensors(operator_outputs) + + def GetTensors(self, tf_tensors_index): + return_list = list() + for tensor_idx in tf_tensors_index: + if (tensor_idx < 0): + return_list.append(Tensor(tensor_idx, 0, 0)) + continue + tf_tensor = self.tf_subgraph.Tensors(tensor_idx) + buffer_idx = tf_tensor.Buffer() + tf_buffer = self.tf_model.Buffers(buffer_idx) + return_list.append(Tensor(tensor_idx, tf_tensor, tf_buffer)) + return return_list + + def AppendOperator(self, operator): + self.operators_in_list.append(operator) + + opcode_str = operator.opcode_str + if opcode_str not in self.operators_per_type: + self.operators_per_type[opcode_str] = list() + self.operators_per_type[opcode_str].append(operator) + + def PrintAll(self): + print('') + self.PrintAllOperatorsInList() + print('') + self.PrintAllTypesInfo() + print('') + + def PrintAllOperatorsInList(self): + for operator in self.operators_in_list: + operator.PrintInfo(self.perf_predictor) + print('') + + def PrintAllTypesInfo(self): + print("Number of all operator types: {0}".format(len(self.operators_per_type))) + + # number of instructions of all operator types + total_instrs = 0 + + # (a string of the operator type, a list of operators which are the same operator type) + for type_str, oper_list in self.operators_per_type.items(): + # this operator type can be computed? + can_compute = oper_list[0].operation.can_compute + + # number of occurrence of this operator type + occur = len(oper_list) + + # total number of instructions of the same operator types + if can_compute: + instrs = sum(operator.operation.TotalInstrNum() for operator in oper_list) + total_instrs = total_instrs + instrs + instrs = "{:,}".format(instrs) + else: + instrs = "???" + + print("\t{type_str:38}: {occur:4} \t (instrs: {instrs})".format( + type_str=type_str, occur=occur, instrs=instrs)) + + total_instrs = "{:,}".format(total_instrs) + print("{0:46}: {1:4} \t (total instrs: {2})".format("Number of all operators", + len(self.operators_in_list), + total_instrs)) diff --git a/tools/tflitefile_tool/operator_wrapping.py b/tools/tflitefile_tool/operator_wrapping.py new file mode 100755 index 000000000..1b7f55a4c --- /dev/null +++ b/tools/tflitefile_tool/operator_wrapping.py @@ -0,0 +1,120 @@ +#!/usr/bin/python + +import tflite.Operator +import tflite.OperatorCode +import tflite.BuiltinOperator +import tflite.ActivationFunctionType +from tensor_wrapping import Tensor +from operation import Operation +from perf_predictor import PerfPredictor + + +# Match enum value integer to name string +# Assumption 1: enum value is defined by old style (can be used on python 2) +# Assumption 2: when class define enum value, only constant value is defined and methods are not defined +# Assumption 3: only integer value is set by constant definition +def BuildEnumClassStrMap(obj): + ret = {} + for fieldName in dir(obj): + if (not fieldName.startswith('_')): + fieldValue = getattr(obj, fieldName) + if (isinstance(fieldValue, (int))): + ret[fieldValue] = fieldName + return ret + + +class EnumStrMaps(): + BuiltinOpcode = BuildEnumClassStrMap(tflite.BuiltinOperator.BuiltinOperator()) + ActivationFunctionType = BuildEnumClassStrMap( + tflite.ActivationFunctionType.ActivationFunctionType()) + BuiltinOptions = BuildEnumClassStrMap(tflite.BuiltinOptions.BuiltinOptions()) + + +def GetStrTensorIndex(tensors): + return_string = "[" + for idx in range(len(tensors)): + if idx != 0: + return_string += ", " + return_string += str(tensors[idx].tensor_idx) + return_string += "]" + return return_string + + +def GetAttribute(o, *args): + import functools + return functools.reduce(getattr, args, o) + + +def BuildBuiltinOptionGen(): + bo_gen = {} + for val_enum in EnumStrMaps.BuiltinOptions: + val_str = EnumStrMaps.BuiltinOptions[val_enum] + try: + # Dynamically import Builtin Option classes + # 0 (NONE) is the only exception that does not have no corresponding flatbuffer-generated class + module = __import__("tflite." + val_str) + bo_gen[val_enum] = GetAttribute(module, val_str, val_str) + except ImportError as e: + assert val_enum == 0 and val_str == "NONE" + return bo_gen + + +class OptionLoader: + builtinOptionGen = BuildBuiltinOptionGen() + + @staticmethod + def GetBuiltinOptions(options_type, options_table): + options = OptionLoader.builtinOptionGen[options_type]() + options.Init(options_table.Bytes, options_table.Pos) + return options + + +class Operator(object): + def __init__(self, operator_idx, tf_operator, input_tensors, output_tensors, + opcode_str): + self.operator_idx = operator_idx + self.tf_operator = tf_operator + self.inputs = input_tensors + self.outputs = output_tensors + self.opcode_str = opcode_str + self.operation = Operation(self.tf_operator, self.opcode_str, self.inputs, + self.outputs) + + def PrintInfo(self, perf_predictor=None): + # total instruction num + instrs = "{:,}".format( + self.operation.TotalInstrNum()) if self.operation.can_compute else "???" + + # total operation cycles + cycles = "{:,}".format( + (perf_predictor.PredictCycles(self.operation) + )) if self.operation.can_compute and perf_predictor != None else "???" + + print("Operator {0}: {1} (instrs: {2}, cycls: {3})".format( + self.operator_idx, self.opcode_str, instrs, cycles)) + + self.PrintOptionInfo() + + print("\tInput Tensors" + GetStrTensorIndex(self.inputs)) + for tensor in self.inputs: + tensor.PrintInfo("\t\t") + print("\tOutput Tensors" + GetStrTensorIndex(self.outputs)) + for tensor in self.outputs: + tensor.PrintInfo("\t\t") + + def PrintOptionInfo(self): + # FIXME: workaround for ops such as custom + try: + options = OptionLoader.GetBuiltinOptions( + self.tf_operator.BuiltinOptionsType(), self.tf_operator.BuiltinOptions()) + except KeyError: + return + + # fused activation function + try: + activation_code = options.FusedActivationFunction() + fused_activation = EnumStrMaps.ActivationFunctionType[activation_code] + print("\tFused Activation: " + fused_activation) + except AttributeError: + # This operator does not support FusedActivationFunction + pass diff --git a/tools/tflitefile_tool/perf_predictor.py b/tools/tflitefile_tool/perf_predictor.py new file mode 100755 index 000000000..8880c8e71 --- /dev/null +++ b/tools/tflitefile_tool/perf_predictor.py @@ -0,0 +1,15 @@ +#!/usr/bin/python + +from operation import Operation + + +class PerfPredictor(object): + def __init__(self, add_cycle=1, mul_cycle=1, nonlinear_cycle=1): + self.add_cycle = add_cycle + self.mul_cycle = mul_cycle + self.nonlinear_cycle = nonlinear_cycle + + def PredictCycles(self, operation): + return (operation.add_instr_num * self.add_cycle + + operation.mul_instr_num * self.mul_cycle + + operation.nonlinear_instr_num * self.nonlinear_cycle) diff --git a/tools/tflitefile_tool/select_operator.py b/tools/tflitefile_tool/select_operator.py new file mode 100755 index 000000000..55ca1acd9 --- /dev/null +++ b/tools/tflitefile_tool/select_operator.py @@ -0,0 +1,825 @@ +#!/usr/bin/python +import os +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')) + +import flatbuffers +import tflite.Model +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): + lines = oplist_file.readlines() + opcode_list = [] + + for line in lines: + words = line.split() + for word in words: + if word.isdigit(): + opcode_list.append(int(word)) + else: + opcode_range = word.split('-') + if ((len(opcode_range) == 2) and opcode_range[0].isdigit() + and opcode_range[1].isdigit()): + start = int(opcode_range[0]) + end = int(opcode_range[1]) + for num in range(start, end + 1): + opcode_list.append(int(num)) + else: + print("Error: Cannot get operator list") + print( + "Please pass operators as operator index or range list split by space and/or line" + ) + exit(1) + + if len(opcode_list) == 0: + print("No selected operator") + exit(1) + + return opcode_list + + +def GenerateOperatorCodes(new_builder, sample_model, used_operators_dic): + operator_code_num = sample_model.OperatorCodesLength() + new_operator_code_list = [] + new_operator_code_string_list = {} + + if operator_code_num == 0: + return 0 + + # Create operator_code string + for operator_code_idx in range(operator_code_num): + if operator_code_idx in used_operators_dic: + 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) + + # Create tables of operator_code + for operator_code_idx in range(operator_code_num): + if operator_code_idx in used_operators_dic: + operator_code = sample_model.OperatorCodes(operator_code_idx) + + # Create operator_code table + tflite.OperatorCode.OperatorCodeStart(new_builder) + 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]) + new_operator_code = tflite.OperatorCode.OperatorCodeEnd(new_builder) + new_operator_code_list.append(new_operator_code) + + # Create operator_code vector + new_operator_code_num = len(new_operator_code_list) + tflite.Model.ModelStartOperatorCodesVector(new_builder, new_operator_code_num) + for operator_code_idx in reversed(range(new_operator_code_num)): + new_builder.PrependUOffsetTRelative(new_operator_code_list[operator_code_idx]) + + return new_builder.EndVector(new_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) + for min_idx in reversed(range(min_num)): + new_builder.PrependFloat32(selected_quantization.Min(min_idx)) + new_min = new_builder.EndVector(min_num) + + # Create max vector + max_num = selected_quantization.MaxLength() + if max_num != 0: + 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) + + # Create scale vector + scale_num = selected_quantization.ScaleLength() + if scale_num != 0: + 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) + + # Create zero_point vector + zeropoint_num = selected_quantization.ZeroPointLength() + if zeropoint_num != 0: + 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) + + # Create quantization + tflite.QuantizationParameters.QuantizationParametersStart(new_builder) + if min_num != 0: + tflite.QuantizationParameters.QuantizationParametersAddMin(new_builder, new_min) + if max_num != 0: + tflite.QuantizationParameters.QuantizationParametersAddMax(new_builder, new_max) + if scale_num != 0: + tflite.QuantizationParameters.QuantizationParametersAddScale( + new_builder, new_scale) + if zeropoint_num != 0: + 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 + shape_num = selected_tensor.ShapeLength() + tflite.Tensor.TensorStartShapeVector(new_builder, shape_num) + if shape_num != 0: + for shape_idx in reversed(range(shape_num)): + new_builder.PrependInt32(selected_tensor.Shape(shape_idx)) + new_shape = new_builder.EndVector(shape_num) + + # Create tensor_type + tensor_type = selected_tensor.Type() + + # Create input vector for tensor + buffer_idx = selected_tensor.Buffer() + new_buffer_idx = used_buffers_dic[buffer_idx] + + # Create name string + name_string = selected_tensor.Name() + if name_string != "": + new_name = new_builder.CreateString(name_string) + + # Create quantization + quantization = selected_tensor.Quantization() + if quantization != 0: + new_quantization = GenerateQuantization(new_builder, quantization) + + # Create tensor + tflite.Tensor.TensorStart(new_builder) + tflite.Tensor.TensorAddShape(new_builder, new_shape) + tflite.Tensor.TensorAddType(new_builder, tensor_type) + tflite.Tensor.TensorAddBuffer(new_builder, new_buffer_idx) + if name_string != "": + tflite.Tensor.TensorAddName(new_builder, new_name) + if quantization != 0: + tflite.Tensor.TensorAddQuantization(new_builder, new_quantization) + + 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 = [] + + if tensor_num == 0: + return 0 + + for tensor_idx in range(tensor_num): + if tensor_idx in used_tensors_dic: + selected_tensor = selected_subgraph.Tensors(tensor_idx) + new_tensor = GenerateTensor(new_builder, selected_tensor, used_buffers_dic) + new_tensor_list.append(new_tensor) + + new_tensor_num = len(new_tensor_list) + if new_tensor_num == 0: + return 0 + + tflite.SubGraph.SubGraphStartTensorsVector(new_builder, new_tensor_num) + for new_tensor in reversed(new_tensor_list): + new_builder.PrependUOffsetTRelative(new_tensor) + + return new_builder.EndVector(new_tensor_num) + + +import tflite.Conv2DOptions +import tflite.DepthwiseConv2DOptions +import tflite.Pool2DOptions +import tflite.FullyConnectedOptions +import tflite.SoftmaxOptions +import tflite.ConcatenationOptions +import tflite.ReshapeOptions +import tflite.AddOptions +import tflite.SubOptions +import tflite.MulOptions +import tflite.DivOptions +import tflite.ResizeBilinearOptions +import tflite.StridedSliceOptions +import tflite.CastOptions +import tflite.TopKV2Options +import tflite.GatherOptions + + +def GenerateBuiltinOption(new_builder, selected_builtin_option, builtin_option_type): + + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().Conv2DOptions: + + conv2d_options = tflite.Conv2DOptions.Conv2DOptions() + 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()) + return tflite.Conv2DOptions.Conv2DOptionsEnd(new_builder) + + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions( + ).DepthwiseConv2DOptions: + + depthconv2d_option = tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptions() + 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()) + return tflite.DepthwiseConv2DOptions.DepthwiseConv2DOptionsEnd(new_builder) + + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().Pool2DOptions: + + pool2d_option = tflite.Pool2DOptions.Pool2DOptions() + pool2d_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos) + + tflite.Pool2DOptions.Pool2DOptionsStart(new_builder) + 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()) + return tflite.Pool2DOptions.Pool2DOptionsEnd(new_builder) + + 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()) + return tflite.FullyConnectedOptions.FullyConnectedOptionsEnd(new_builder) + + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().SoftmaxOptions: + + softmax_option = tflite.SoftmaxOptions.SoftmaxOptions() + softmax_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos) + + tflite.SoftmaxOptions.SoftmaxOptionsStart(new_builder) + tflite.SoftmaxOptions.SoftmaxOptionsAddBeta(new_builder, softmax_option.Beta()) + return tflite.SoftmaxOptions.SoftmaxOptionsEnd(new_builder) + + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().ConcatenationOptions: + + concat_option = tflite.ConcatenationOptions.ConcatenationOptions() + 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()) + return tflite.ConcatenationOptions.ConcatenationOptionsEnd(new_builder) + + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().ReshapeOptions: + + reshape_option = tflite.ReshapeOptions.ReshapeOptions() + reshape_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos) + + shape_num = reshape_option.NewShapeLength() + if shape_num != 0: + 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) + new_shape = new_builder.EndVector(shape_num) + + tflite.ReshapeOptions.ReshapeOptionsStart(new_builder) + if shape_num != 0: + tflite.ReshapeOptions.ReshapeOptionsAddNewShape(new_builder, new_shape) + return tflite.ReshapeOptions.ReshapeOptionsEnd(new_builder) + + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().AddOptions: + + add_option = tflite.AddOptions.AddOptions() + add_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos) + + tflite.AddOptions.AddOptionsStart(new_builder) + tflite.AddOptions.AddOptionsAddFusedActivationFunction( + new_builder, add_option.FusedActivationFunction()) + return tflite.AddOptions.AddOptionsEnd(new_builder) + + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().SubOptions: + + sub_option = tflite.SubOptions.SubOptions() + sub_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos) + + tflite.SubOptions.SubOptionsStart(new_builder) + tflite.SubOptions.SubOptionsAddFusedActivationFunction( + new_builder, sub_option.FusedActivationFunction()) + return tflite.SubOptions.SubOptionsEnd(new_builder) + + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().MulOptions: + + mul_option = tflite.MulOptions.MulOptions() + mul_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos) + + tflite.MulOptions.MulOptionsStart(new_builder) + tflite.MulOptions.MulOptionsAddFusedActivationFunction( + new_builder, mul_option.FusedActivationFunction()) + return tflite.MulOptions.MulOptionsEnd(new_builder) + + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().DivOptions: + + div_option = tflite.DivOptions.DivOptions() + div_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos) + + tflite.DivOptions.DivOptionsStart(new_builder) + tflite.DivOptions.DivOptionsAddFusedActivationFunction( + new_builder, div_option.FusedActivationFunction()) + return tflite.DivOptions.DivOptionsEnd(new_builder) + + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions( + ).ResizeBilinearOptions: + + resize_bilinear_option = tflite.ResizeBilinearOptions.ResizeBilinearOptions() + resize_bilinear_option.Init(selected_builtin_option.Bytes, + selected_builtin_option.Pos) + + tflite.ResizeBilinearOptions.ResizeBilinearOptionsStart(new_builder) + tflite.ResizeBilinearOptions.ResizeBilinearOptionsAddAlignCorners( + new_builder, resize_bilinear_option.AlignCorners()) + return tflite.ResizeBilinearOptions.ResizeBilinearOptionsEnd(new_builder) + + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().StridedSliceOptions: + + stride_slice_option = tflite.StridedSliceOptions.StridedSliceOptions() + stride_slice_option.Init(selected_builtin_option.Bytes, + selected_builtin_option.Pos) + + tflite.StridedSliceOptions.StridedSliceOptionsStart(new_builder) + tflite.StridedSliceOptions.StridedSliceOptionsAddBeginMask( + new_builder, stride_slice_option.BeginMask()) + tflite.StridedSliceOptions.StridedSliceOptionsAddEndMask( + new_builder, stride_slice_option.EndMask()) + tflite.StridedSliceOptions.StridedSliceOptionsAddEllipsisMask( + new_builder, stride_slice_option.EllipsisMask()) + tflite.StridedSliceOptions.StridedSliceOptionsAddNewAxisMask( + new_builder, stride_slice_option.NewAxisMask()) + tflite.StridedSliceOptions.StridedSliceOptionsAddShrinkAxisMask( + new_builder, stride_slice_option.ShrinkAxisMask()) + + return tflite.StridedSliceOptions.StridedSliceOptionsEnd(new_builder) + + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().CastOptions: + + cast_option = tflite.CastOptions.CastOptions() + cast_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos) + + tflite.CastOptions.CastOptionsStart(new_builder) + return tflite.CastOptions.CastOptionsEnd(new_builder) + + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().TopKV2Options: + + topkv2_option = tflite.TopKV2Options.TopKV2Options() + topkv2_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos) + + tflite.TopKV2Options.TopKV2OptionsStart(new_builder) + return tflite.TopKV2Options.TopKV2OptionsEnd(new_builder) + + if builtin_option_type == tflite.BuiltinOptions.BuiltinOptions().GatherOptions: + + gather_option = tflite.GatherOptions.GatherOptions() + gather_option.Init(selected_builtin_option.Bytes, selected_builtin_option.Pos) + + tflite.GatherOptions.GatherOptionsStart(new_builder) + tflite.GatherOptions.GatherOptionsAddAxis(new_builder, gather_option.Axis()) + return tflite.GatherOptions.GatherOptionsEnd(new_builder) + + # Cannot handle builtin option type yet + return 0 + + +def GenerateOperator(new_builder, selected_operator, used_tensors_dic, + used_operators_dic): + + # define opcode_index + opcode_index = selected_operator.OpcodeIndex() + new_opcode_index = used_operators_dic[opcode_index] + + # create input vector + input_num = selected_operator.InputsLength() + if input_num != 0: + new_input_list = [] + tflite.Operator.OperatorStartInputsVector(new_builder, input_num) + for input_idx in reversed(range(input_num)): + input_tensor_idx = selected_operator.Inputs(input_idx) + new_input_tensor_idx = used_tensors_dic[input_tensor_idx] + new_builder.PrependInt32(new_input_tensor_idx) + new_input_list.append(new_input_tensor_idx) + new_input = new_builder.EndVector(input_num) + + # create output_vector + output_num = selected_operator.OutputsLength() + if output_num != 0: + tflite.Operator.OperatorStartOutputsVector(new_builder, output_num) + for output_idx in reversed(range(output_num)): + output_tensor_idx = selected_operator.Outputs(output_idx) + new_output_tensor_idx = used_tensors_dic[output_tensor_idx] + new_builder.PrependInt32(new_output_tensor_idx) + new_output = new_builder.EndVector(output_num) + + # Create builtin_option + 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) + + # Create custum option vector + custom_option_num = selected_operator.CustomOptionsLength() + if custom_option_num != 0: + tflite.Operator.OperatorStartCustomOptionsVector(new_builder, custom_option_num) + for custom_option_idx in reversed(range(custom_option_num)): + new_builder.PrependUint8(selected_operator.CustomOptions(custom_option_idx)) + new_custom_option = new_builder.EndVector(custom_option_num) + + # Create custum option type + custom_option_type = selected_operator.CustomOptionsFormat() + + # Create operator + tflite.Operator.OperatorStart(new_builder) + tflite.Operator.OperatorAddOpcodeIndex(new_builder, new_opcode_index) + if input_num != 0: + tflite.Operator.OperatorAddInputs(new_builder, new_input) + if output_num != 0: + tflite.Operator.OperatorAddOutputs(new_builder, new_output) + tflite.Operator.OperatorAddBuiltinOptionsType(new_builder, builtin_option_type) + 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.OperatorAddCustomOptionsFormat(new_builder, custom_option_type) + return tflite.Operator.OperatorEnd(new_builder) + + +def GenerateOperators(new_builder, selected_subgraph, opcode_list, used_tensors_dic, + used_operators_dic): + operator_num = selected_subgraph.OperatorsLength() + new_operator_list = [] + + if operator_num == 0: + return 0 + + 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, used_operators_dic) + new_operator_list.append(new_operator) + + new_operator_num = len(new_operator_list) + if new_operator_num == 0: + return 0 + + tflite.SubGraph.SubGraphStartOperatorsVector(new_builder, new_operator_num) + for new_operator in reversed(new_operator_list): + new_builder.PrependUOffsetTRelative(new_operator) + + 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, + used_operators_dic): + + # Tensors + 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) + if new_input_tensor_num != 0: + tflite.SubGraph.SubGraphStartInputsVector(new_builder, new_input_tensor_num) + for input_tensor_idx in reversed(new_input_tensor): + new_input_tensor_idx = used_tensors_dic[input_tensor_idx] + new_builder.PrependInt32(new_input_tensor_idx) + new_inputs = new_builder.EndVector(new_input_tensor_num) + + # Create output vector for subgraph table + new_output_tensor_num = len(new_output_tensor) + if new_output_tensor_num != 0: + tflite.SubGraph.SubGraphStartInputsVector(new_builder, new_output_tensor_num) + for output_tensor_idx in reversed(new_output_tensor): + new_output_tensor_idx = used_tensors_dic[output_tensor_idx] + new_builder.PrependInt32(new_output_tensor_idx) + new_outputs = new_builder.EndVector(new_output_tensor_num) + + # Operators + operators = GenerateOperators(new_builder, selected_subgraph, opcode_list, + used_tensors_dic, used_operators_dic) + + # Name + subgraph_name = selected_subgraph.Name() + have_name = False + if subgraph_name != "": + have_name = True + new_subgraph_name = new_builder.CreateString(subgraph_name) + + tflite.SubGraph.SubGraphStart(new_builder) + tflite.SubGraph.SubGraphAddTensors(new_builder, tensors) + if new_input_tensor_num != 0: + tflite.SubGraph.SubGraphAddInputs(new_builder, new_inputs) + if new_output_tensor_num != 0: + tflite.SubGraph.SubGraphAddOutputs(new_builder, new_outputs) + tflite.SubGraph.SubGraphAddOperators(new_builder, operators) + if have_name: + tflite.SubGraph.SubGraphAddName(new_builder, new_subgraph_name) + + 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, + used_operators_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, used_operators_dic) + new_subgraph_list.append(new_subgraph) + + new_subgraph_num = 1 + tflite.Model.ModelStartSubgraphsVector(new_builder, new_subgraph_num) + for subgraph_idx in reversed(range(new_subgraph_num)): + new_builder.PrependUOffsetTRelative(new_subgraph_list[subgraph_idx]) + + 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 = {} + new_buffer_list = [] + + if buffer_num == 0: + return 0 + + # Create data vector for buffer table + for buffer_idx in range(buffer_num): + buffer = sample_model.Buffers(buffer_idx) + buffer_length = buffer.DataLength() + + if (buffer_length != 0) and (buffer_idx in used_buffers_dic): + tflite.Buffer.BufferStartDataVector(new_builder, buffer_length) + for buffer_data_idx in reversed(range(buffer_length)): + new_builder.PrependUint8(buffer.Data(buffer_data_idx)) + new_buffer = new_builder.EndVector(buffer_length) + new_buffer_data_list[buffer_idx] = new_buffer + + # Create tables of buffer + for buffer_idx in range(buffer_num): + buffer = sample_model.Buffers(buffer_idx) + + if buffer_idx in used_buffers_dic: + # Create buffer table + tflite.Buffer.BufferStart(new_builder) + if buffer.DataLength() != 0: + tflite.Buffer.BufferAddData(new_builder, new_buffer_data_list[buffer_idx]) + new_buffer = tflite.Buffer.BufferEnd(new_builder) + new_buffer_list.append(new_buffer) + + # Create buffer vector + new_buffer_num = len(new_buffer_list) + if new_buffer_num == 0: + return 0 + + tflite.Model.ModelStartBuffersVector(new_builder, new_buffer_num) + for new_buffer_idx in reversed(range(new_buffer_num)): + new_builder.PrependUOffsetTRelative(new_buffer_list[new_buffer_idx]) + + 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, + used_operators_dic): + # uint + version = sample_model.Version() + + # pointer of operator code 'table' vector + operator_codes = GenerateOperatorCodes(new_builder, sample_model, used_operators_dic) + + # subgraphs + subgraphs = GenerateSubgraphs(new_builder, sample_model, opcode_list, + new_input_tensors, new_output_tensors, used_tensors_dic, + used_buffers_dic, used_operators_dic) + + # description + description_string = new_builder.CreateString(sample_model.Description()) + + # buffers + buffers = GenerateBuffers(new_builder, sample_model, used_buffers_dic) + + # Generate model + tflite.Model.ModelStart(new_builder) + tflite.Model.ModelAddVersion(new_builder, version) + tflite.Model.ModelAddOperatorCodes(new_builder, operator_codes) + tflite.Model.ModelAddSubgraphs(new_builder, subgraphs) + tflite.Model.ModelAddDescription(new_builder, description_string) + tflite.Model.ModelAddBuffers(new_builder, buffers) + + 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.PrependByte(0x33) + new_builder.PrependByte(0x4c) + new_builder.PrependByte(0x46) + new_builder.PrependByte(0x54) + + new_builder.PrependUOffsetTRelative(new_model) + new_builder.finished = True + return new_builder.Head() + + +def main(args): + input_model_file = args.input_model + oplist_file = args.opcode_list + output_model_file = args.output_model + + # Parse operator list file + opcode_list = GetOperatorList(oplist_file) + + # Get sample model and subgraph + # We use only 1st subgraph + sample_buf = input_model_file.read() + sample_buf = bytearray(sample_buf) + sample_model = tflite.Model.Model.GetRootAsModel(sample_buf, 0) + sample_subgraph = sample_model.Subgraphs(0) + + # Collect used tensor & used operator + used_tensors = [] + used_operators = [] + + for opcode_idx in opcode_list: + opcode = sample_subgraph.Operators(opcode_idx) + for input_idx in range(opcode.InputsLength()): + input_tensor_idx = opcode.Inputs(input_idx) + if not input_tensor_idx in used_tensors: + # default: same as input sample + used_tensors.append(input_tensor_idx) + + for output_idx in range(opcode.OutputsLength()): + output_tensor_idx = opcode.Outputs(output_idx) + if not output_tensor_idx in used_tensors: + # default: same as input sample + used_tensors.append(output_tensor_idx) + + opcode_idx = opcode.OpcodeIndex() + if not opcode_idx in used_operators: + used_operators.append(opcode_idx) + + used_tensors.sort() + used_operators.sort() + + # Collect used buffer + # buffer[0] should be blank. So it should start from 1 + used_buffers = [0] + + for used_tensor in used_tensors: + # key and value is same in prepare phase + buf_idx = (sample_subgraph.Tensors(used_tensor)).Buffer() + used_buffers.append(buf_idx) + used_buffers.sort() + + # Assign new index for operator + used_operators_dic = {} + + for new_operator_idx in range(len(used_operators)): + sample_operator_idx = used_operators[new_operator_idx] + used_operators_dic[sample_operator_idx] = new_operator_idx + + # Assign new index for tensor + used_tensors_dic = {} + + for new_tensor_idx in range(len(used_tensors)): + sample_tensor_idx = used_tensors[new_tensor_idx] + used_tensors_dic[sample_tensor_idx] = new_tensor_idx + + # Assign new index for buffer + used_buffers_dic = {} + + for new_buffer_idx in range(len(used_buffers)): + sample_buffer_idx = used_buffers[new_buffer_idx] + used_buffers_dic[sample_buffer_idx] = new_buffer_idx + + # Find input & output tensor in new model + new_input_tensors = used_tensors[:] + new_output_tensors = used_tensors[:] + + for opcode_idx in opcode_list: + opcode = sample_subgraph.Operators(opcode_idx) + for input_idx in range(opcode.InputsLength()): + input_tensor_idx = opcode.Inputs(input_idx) + if input_tensor_idx in new_output_tensors: + new_output_tensors.remove(input_tensor_idx) + if input_tensor_idx in new_input_tensors: + matched_buffer_idx = sample_subgraph.Tensors(input_tensor_idx).Buffer() + matched_buffer = sample_model.Buffers(matched_buffer_idx) + if matched_buffer.DataLength() != 0: + new_input_tensors.remove(input_tensor_idx) + + for output_idx in range(opcode.OutputsLength()): + output_tensor_idx = opcode.Outputs(output_idx) + if output_tensor_idx in new_input_tensors: + new_input_tensors.remove(output_tensor_idx) + if output_tensor_idx in new_output_tensors: + matched_buffer_idx = sample_subgraph.Tensors(output_tensor_idx).Buffer() + matched_buffer = sample_model.Buffers(matched_buffer_idx) + if matched_buffer.DataLength() != 0: + new_output_tensors.remove(input_tensor_idx) + + new_input_tensors_newidx = [] + new_output_tensors_newidx = [] + + for input_tensor_idx in new_input_tensors: + new_input_tensors_newidx.append(used_tensors_dic[input_tensor_idx]) + for output_tensor_idx in new_output_tensors: + new_output_tensors_newidx.append(used_tensors_dic[output_tensor_idx]) + + print("Input tensor(s): " + str(new_input_tensors_newidx)) + print("Output tensor(s): " + str(new_output_tensors_newidx)) + + # 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, + used_operators_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") + args = arg_parser.parse_args() + + # Call main function + main(args) diff --git a/tools/tflitefile_tool/tensor_wrapping.py b/tools/tflitefile_tool/tensor_wrapping.py new file mode 100755 index 000000000..b1fba57d2 --- /dev/null +++ b/tools/tflitefile_tool/tensor_wrapping.py @@ -0,0 +1,54 @@ +#!/usr/bin/python + +import tflite.Tensor +import tflite.TensorType + +TensorTypeList = {} + + +def SetTensorTypeStr(): + tensorTypeObj = tflite.TensorType.TensorType() + + for fieldName in dir(tensorTypeObj): + if (not fieldName.startswith('_')): + fieldValue = getattr(tensorTypeObj, fieldName) + if (isinstance(fieldValue, (int))): + TensorTypeList[fieldValue] = fieldName + + +class Tensor(object): + def __init__(self, tensor_idx, tf_tensor, tf_buffer): + self.tensor_idx = tensor_idx + self.tf_tensor = tf_tensor + self.tf_buffer = tf_buffer + + def PrintInfo(self, depth_str=""): + print_str = "" + if self.tensor_idx < 0: + print_str = "Tensor {0:4}".format(self.tensor_idx) + else: + buffer_idx = self.tf_tensor.Buffer() + isEmpty = "Filled" + if (self.tf_buffer.DataLength() == 0): + isEmpty = " Empty" + shape_str = self.GetShapeString() + type_name = TensorTypeList[self.tf_tensor.Type()] + + shape_name = "" + if self.tf_tensor.Name() != 0: + shape_name = self.tf_tensor.Name() + + print_str = "Tensor {0:4} : buffer {1:4} | {2} | {3:7} | Shape {4} ({5})".format( + self.tensor_idx, buffer_idx, isEmpty, type_name, shape_str, shape_name) + print(depth_str + print_str) + + def GetShapeString(self): + if self.tf_tensor.ShapeLength() == 0: + return "Scalar" + return_string = "[" + for shape_idx in range(self.tf_tensor.ShapeLength()): + if (shape_idx != 0): + return_string += ", " + return_string += str(self.tf_tensor.Shape(shape_idx)) + return_string += "]" + return return_string diff --git a/tools/tflitefile_tool/tflite/ActivationFunctionType.py b/tools/tflitefile_tool/tflite/ActivationFunctionType.py new file mode 100644 index 000000000..a32353964 --- /dev/null +++ b/tools/tflitefile_tool/tflite/ActivationFunctionType.py @@ -0,0 +1,12 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + + +class ActivationFunctionType(object): + NONE = 0 + RELU = 1 + RELU_N1_TO_1 = 2 + RELU6 = 3 + TANH = 4 + SIGN_BIT = 5 diff --git a/tools/tflitefile_tool/tflite/AddOptions.py b/tools/tflitefile_tool/tflite/AddOptions.py new file mode 100644 index 000000000..c9f3387ca --- /dev/null +++ b/tools/tflitefile_tool/tflite/AddOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class AddOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsAddOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = AddOptions() + x.Init(buf, n + offset) + return x + + # AddOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # AddOptions + def FusedActivationFunction(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/ArgMaxOptions.py b/tools/tflitefile_tool/tflite/ArgMaxOptions.py new file mode 100644 index 000000000..23cbfd731 --- /dev/null +++ b/tools/tflitefile_tool/tflite/ArgMaxOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class ArgMaxOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsArgMaxOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = ArgMaxOptions() + x.Init(buf, n + offset) + return x + + # ArgMaxOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # ArgMaxOptions + def OutputType(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + +def ArgMaxOptionsStart(builder): + builder.StartObject(1) + + +def ArgMaxOptionsAddOutputType(builder, outputType): + builder.PrependInt8Slot(0, outputType, 0) + + +def ArgMaxOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/ArgMinOptions.py b/tools/tflitefile_tool/tflite/ArgMinOptions.py new file mode 100644 index 000000000..6a2dcdfe1 --- /dev/null +++ b/tools/tflitefile_tool/tflite/ArgMinOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class ArgMinOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsArgMinOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = ArgMinOptions() + x.Init(buf, n + offset) + return x + + # ArgMinOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # ArgMinOptions + def OutputType(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + +def ArgMinOptionsStart(builder): + builder.StartObject(1) + + +def ArgMinOptionsAddOutputType(builder, outputType): + builder.PrependInt8Slot(0, outputType, 0) + + +def ArgMinOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/BatchToSpaceNDOptions.py b/tools/tflitefile_tool/tflite/BatchToSpaceNDOptions.py new file mode 100644 index 000000000..48a7d4c23 --- /dev/null +++ b/tools/tflitefile_tool/tflite/BatchToSpaceNDOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class BatchToSpaceNDOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsBatchToSpaceNDOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = BatchToSpaceNDOptions() + x.Init(buf, n + offset) + return x + + # BatchToSpaceNDOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +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 new file mode 100644 index 000000000..5c057b6bf --- /dev/null +++ b/tools/tflitefile_tool/tflite/BidirectionalSequenceRNNOptions.py @@ -0,0 +1,51 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class BidirectionalSequenceRNNOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsBidirectionalSequenceRNNOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = BidirectionalSequenceRNNOptions() + x.Init(buf, n + offset) + return x + + # BidirectionalSequenceRNNOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # BidirectionalSequenceRNNOptions + def TimeMajor(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos) + return 0 + + # BidirectionalSequenceRNNOptions + def FusedActivationFunction(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/Buffer.py b/tools/tflitefile_tool/tflite/Buffer.py new file mode 100644 index 000000000..d3fa8e9de --- /dev/null +++ b/tools/tflitefile_tool/tflite/Buffer.py @@ -0,0 +1,61 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class Buffer(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsBuffer(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = Buffer() + x.Init(buf, n + offset) + return x + + # Buffer + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # Buffer + def Data(self, j): + 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 0 + + # Buffer + def DataAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Uint8Flags, o) + return 0 + + # Buffer + def DataLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/BuiltinOperator.py b/tools/tflitefile_tool/tflite/BuiltinOperator.py new file mode 100644 index 000000000..2beda098e --- /dev/null +++ b/tools/tflitefile_tool/tflite/BuiltinOperator.py @@ -0,0 +1,86 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + + +class BuiltinOperator(object): + ADD = 0 + AVERAGE_POOL_2D = 1 + CONCATENATION = 2 + CONV_2D = 3 + DEPTHWISE_CONV_2D = 4 + DEQUANTIZE = 6 + EMBEDDING_LOOKUP = 7 + FLOOR = 8 + FULLY_CONNECTED = 9 + HASHTABLE_LOOKUP = 10 + L2_NORMALIZATION = 11 + L2_POOL_2D = 12 + LOCAL_RESPONSE_NORMALIZATION = 13 + LOGISTIC = 14 + LSH_PROJECTION = 15 + LSTM = 16 + MAX_POOL_2D = 17 + MUL = 18 + RELU = 19 + RELU_N1_TO_1 = 20 + RELU6 = 21 + RESHAPE = 22 + RESIZE_BILINEAR = 23 + RNN = 24 + SOFTMAX = 25 + SPACE_TO_DEPTH = 26 + SVDF = 27 + TANH = 28 + CONCAT_EMBEDDINGS = 29 + SKIP_GRAM = 30 + CALL = 31 + CUSTOM = 32 + EMBEDDING_LOOKUP_SPARSE = 33 + PAD = 34 + UNIDIRECTIONAL_SEQUENCE_RNN = 35 + GATHER = 36 + BATCH_TO_SPACE_ND = 37 + SPACE_TO_BATCH_ND = 38 + TRANSPOSE = 39 + MEAN = 40 + SUB = 41 + DIV = 42 + SQUEEZE = 43 + UNIDIRECTIONAL_SEQUENCE_LSTM = 44 + STRIDED_SLICE = 45 + BIDIRECTIONAL_SEQUENCE_RNN = 46 + EXP = 47 + TOPK_V2 = 48 + SPLIT = 49 + LOG_SOFTMAX = 50 + DELEGATE = 51 + BIDIRECTIONAL_SEQUENCE_LSTM = 52 + CAST = 53 + PRELU = 54 + MAXIMUM = 55 + ARG_MAX = 56 + MINIMUM = 57 + LESS = 58 + NEG = 59 + PADV2 = 60 + GREATER = 61 + GREATER_EQUAL = 62 + LESS_EQUAL = 63 + SELECT = 64 + SLICE = 65 + SIN = 66 + TRANSPOSE_CONV = 67 + SPARSE_TO_DENSE = 68 + TILE = 69 + EXPAND_DIMS = 70 + EQUAL = 71 + NOT_EQUAL = 72 + LOG = 73 + SUM = 74 + SQRT = 75 + RSQRT = 76 + SHAPE = 77 + POW = 78 + ARG_MIN = 79 + FAKE_QUANT = 80 diff --git a/tools/tflitefile_tool/tflite/BuiltinOptions.py b/tools/tflitefile_tool/tflite/BuiltinOptions.py new file mode 100644 index 000000000..5d3040839 --- /dev/null +++ b/tools/tflitefile_tool/tflite/BuiltinOptions.py @@ -0,0 +1,65 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + + +class BuiltinOptions(object): + NONE = 0 + Conv2DOptions = 1 + DepthwiseConv2DOptions = 2 + ConcatEmbeddingsOptions = 3 + LSHProjectionOptions = 4 + Pool2DOptions = 5 + SVDFOptions = 6 + RNNOptions = 7 + FullyConnectedOptions = 8 + SoftmaxOptions = 9 + ConcatenationOptions = 10 + AddOptions = 11 + L2NormOptions = 12 + LocalResponseNormalizationOptions = 13 + LSTMOptions = 14 + ResizeBilinearOptions = 15 + CallOptions = 16 + ReshapeOptions = 17 + SkipGramOptions = 18 + SpaceToDepthOptions = 19 + EmbeddingLookupSparseOptions = 20 + MulOptions = 21 + PadOptions = 22 + GatherOptions = 23 + BatchToSpaceNDOptions = 24 + SpaceToBatchNDOptions = 25 + TransposeOptions = 26 + ReducerOptions = 27 + SubOptions = 28 + DivOptions = 29 + SqueezeOptions = 30 + SequenceRNNOptions = 31 + StridedSliceOptions = 32 + ExpOptions = 33 + TopKV2Options = 34 + SplitOptions = 35 + LogSoftmaxOptions = 36 + CastOptions = 37 + DequantizeOptions = 38 + MaximumMinimumOptions = 39 + ArgMaxOptions = 40 + LessOptions = 41 + NegOptions = 42 + PadV2Options = 43 + GreaterOptions = 44 + GreaterEqualOptions = 45 + LessEqualOptions = 46 + SelectOptions = 47 + SliceOptions = 48 + TransposeConvOptions = 49 + SparseToDenseOptions = 50 + TileOptions = 51 + ExpandDimsOptions = 52 + EqualOptions = 53 + NotEqualOptions = 54 + ShapeOptions = 55 + PowOptions = 56 + ArgMinOptions = 57 + FakeQuantOptions = 58 diff --git a/tools/tflitefile_tool/tflite/CallOptions.py b/tools/tflitefile_tool/tflite/CallOptions.py new file mode 100644 index 000000000..a82f001fa --- /dev/null +++ b/tools/tflitefile_tool/tflite/CallOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class CallOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsCallOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = CallOptions() + x.Init(buf, n + offset) + return x + + # CallOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # CallOptions + def Subgraph(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/CastOptions.py b/tools/tflitefile_tool/tflite/CastOptions.py new file mode 100644 index 000000000..7f7a1dde3 --- /dev/null +++ b/tools/tflitefile_tool/tflite/CastOptions.py @@ -0,0 +1,50 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class CastOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsCastOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = CastOptions() + x.Init(buf, n + offset) + return x + + # CastOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # CastOptions + def InDataType(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + # CastOptions + def OutDataType(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + +def CastOptionsStart(builder): + builder.StartObject(2) + + +def CastOptionsAddInDataType(builder, inDataType): + builder.PrependInt8Slot(0, inDataType, 0) + + +def CastOptionsAddOutDataType(builder, outDataType): + builder.PrependInt8Slot(1, outDataType, 0) + + +def CastOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/CombinerType.py b/tools/tflitefile_tool/tflite/CombinerType.py new file mode 100644 index 000000000..dfe8afb9f --- /dev/null +++ b/tools/tflitefile_tool/tflite/CombinerType.py @@ -0,0 +1,9 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# 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 new file mode 100644 index 000000000..6ca04a51f --- /dev/null +++ b/tools/tflitefile_tool/tflite/ConcatEmbeddingsOptions.py @@ -0,0 +1,105 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class ConcatEmbeddingsOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsConcatEmbeddingsOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = ConcatEmbeddingsOptions() + x.Init(buf, n + offset) + return x + + # ConcatEmbeddingsOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # ConcatEmbeddingsOptions + def NumChannels(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # ConcatEmbeddingsOptions + def NumColumnsPerChannel(self, j): + 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 0 + + # ConcatEmbeddingsOptions + def NumColumnsPerChannelAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Int32Flags, o) + return 0 + + # ConcatEmbeddingsOptions + def NumColumnsPerChannelLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # ConcatEmbeddingsOptions + def EmbeddingDimPerChannel(self, j): + 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 0 + + # ConcatEmbeddingsOptions + def EmbeddingDimPerChannelAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Int32Flags, o) + return 0 + + # ConcatEmbeddingsOptions + def EmbeddingDimPerChannelLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/ConcatenationOptions.py b/tools/tflitefile_tool/tflite/ConcatenationOptions.py new file mode 100644 index 000000000..ea089ac56 --- /dev/null +++ b/tools/tflitefile_tool/tflite/ConcatenationOptions.py @@ -0,0 +1,50 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class ConcatenationOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsConcatenationOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = ConcatenationOptions() + x.Init(buf, n + offset) + return x + + # ConcatenationOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # ConcatenationOptions + def Axis(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # ConcatenationOptions + def FusedActivationFunction(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/Conv2DOptions.py b/tools/tflitefile_tool/tflite/Conv2DOptions.py new file mode 100644 index 000000000..913729522 --- /dev/null +++ b/tools/tflitefile_tool/tflite/Conv2DOptions.py @@ -0,0 +1,94 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class Conv2DOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsConv2DOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = Conv2DOptions() + x.Init(buf, n + offset) + return x + + # Conv2DOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # Conv2DOptions + def Padding(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + # Conv2DOptions + def StrideW(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # Conv2DOptions + def StrideH(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # Conv2DOptions + def FusedActivationFunction(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + # Conv2DOptions + def DilationWFactor(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 1 + + # Conv2DOptions + def DilationHFactor(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 1 + + +def Conv2DOptionsStart(builder): + builder.StartObject(6) + + +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 Conv2DOptionsAddDilationWFactor(builder, dilationWFactor): + builder.PrependInt32Slot(4, dilationWFactor, 1) + + +def Conv2DOptionsAddDilationHFactor(builder, dilationHFactor): + builder.PrependInt32Slot(5, dilationHFactor, 1) + + +def Conv2DOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/CustomOptionsFormat.py b/tools/tflitefile_tool/tflite/CustomOptionsFormat.py new file mode 100644 index 000000000..18bc07d02 --- /dev/null +++ b/tools/tflitefile_tool/tflite/CustomOptionsFormat.py @@ -0,0 +1,7 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + + +class CustomOptionsFormat(object): + FLEXBUFFERS = 0 diff --git a/tools/tflitefile_tool/tflite/DepthwiseConv2DOptions.py b/tools/tflitefile_tool/tflite/DepthwiseConv2DOptions.py new file mode 100644 index 000000000..9f0b3388f --- /dev/null +++ b/tools/tflitefile_tool/tflite/DepthwiseConv2DOptions.py @@ -0,0 +1,83 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class DepthwiseConv2DOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsDepthwiseConv2DOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = DepthwiseConv2DOptions() + x.Init(buf, n + offset) + return x + + # DepthwiseConv2DOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # DepthwiseConv2DOptions + def Padding(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + # DepthwiseConv2DOptions + def StrideW(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # DepthwiseConv2DOptions + def StrideH(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # DepthwiseConv2DOptions + def DepthMultiplier(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # DepthwiseConv2DOptions + def FusedActivationFunction(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/DequantizeOptions.py b/tools/tflitefile_tool/tflite/DequantizeOptions.py new file mode 100644 index 000000000..fe4cc9a06 --- /dev/null +++ b/tools/tflitefile_tool/tflite/DequantizeOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class DequantizeOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsDequantizeOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = DequantizeOptions() + x.Init(buf, n + offset) + return x + + # DequantizeOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +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 new file mode 100644 index 000000000..53bbae542 --- /dev/null +++ b/tools/tflitefile_tool/tflite/DivOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class DivOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsDivOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = DivOptions() + x.Init(buf, n + offset) + return x + + # DivOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # DivOptions + def FusedActivationFunction(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/EmbeddingLookupSparseOptions.py b/tools/tflitefile_tool/tflite/EmbeddingLookupSparseOptions.py new file mode 100644 index 000000000..12531d3d5 --- /dev/null +++ b/tools/tflitefile_tool/tflite/EmbeddingLookupSparseOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class EmbeddingLookupSparseOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsEmbeddingLookupSparseOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = EmbeddingLookupSparseOptions() + x.Init(buf, n + offset) + return x + + # EmbeddingLookupSparseOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # EmbeddingLookupSparseOptions + def Combiner(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/EqualOptions.py b/tools/tflitefile_tool/tflite/EqualOptions.py new file mode 100644 index 000000000..968712ff8 --- /dev/null +++ b/tools/tflitefile_tool/tflite/EqualOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class EqualOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsEqualOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = EqualOptions() + x.Init(buf, n + offset) + return x + + # EqualOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def EqualOptionsStart(builder): + builder.StartObject(0) + + +def EqualOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/ExpOptions.py b/tools/tflitefile_tool/tflite/ExpOptions.py new file mode 100644 index 000000000..f8c7bd867 --- /dev/null +++ b/tools/tflitefile_tool/tflite/ExpOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class ExpOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsExpOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = ExpOptions() + x.Init(buf, n + offset) + return x + + # ExpOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def ExpOptionsStart(builder): + builder.StartObject(0) + + +def ExpOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/ExpandDimsOptions.py b/tools/tflitefile_tool/tflite/ExpandDimsOptions.py new file mode 100644 index 000000000..2dd8d506c --- /dev/null +++ b/tools/tflitefile_tool/tflite/ExpandDimsOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class ExpandDimsOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsExpandDimsOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = ExpandDimsOptions() + x.Init(buf, n + offset) + return x + + # ExpandDimsOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def ExpandDimsOptionsStart(builder): + builder.StartObject(0) + + +def ExpandDimsOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/FakeQuantOptions.py b/tools/tflitefile_tool/tflite/FakeQuantOptions.py new file mode 100644 index 000000000..fc8023e60 --- /dev/null +++ b/tools/tflitefile_tool/tflite/FakeQuantOptions.py @@ -0,0 +1,72 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class FakeQuantOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsFakeQuantOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = FakeQuantOptions() + x.Init(buf, n + offset) + return x + + # FakeQuantOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # FakeQuantOptions + def Min(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Float32Flags, o + self._tab.Pos) + return 0.0 + + # FakeQuantOptions + def Max(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Float32Flags, o + self._tab.Pos) + return 0.0 + + # FakeQuantOptions + def NumBits(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # FakeQuantOptions + def NarrowRange(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos) + return 0 + + +def FakeQuantOptionsStart(builder): + builder.StartObject(4) + + +def FakeQuantOptionsAddMin(builder, min): + builder.PrependFloat32Slot(0, min, 0.0) + + +def FakeQuantOptionsAddMax(builder, max): + builder.PrependFloat32Slot(1, max, 0.0) + + +def FakeQuantOptionsAddNumBits(builder, numBits): + builder.PrependInt32Slot(2, numBits, 0) + + +def FakeQuantOptionsAddNarrowRange(builder, narrowRange): + builder.PrependBoolSlot(3, narrowRange, 0) + + +def FakeQuantOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/FullyConnectedOptions.py b/tools/tflitefile_tool/tflite/FullyConnectedOptions.py new file mode 100644 index 000000000..59c2a367a --- /dev/null +++ b/tools/tflitefile_tool/tflite/FullyConnectedOptions.py @@ -0,0 +1,50 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class FullyConnectedOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsFullyConnectedOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = FullyConnectedOptions() + x.Init(buf, n + offset) + return x + + # FullyConnectedOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # FullyConnectedOptions + def FusedActivationFunction(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + # FullyConnectedOptions + def WeightsFormat(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + +def FullyConnectedOptionsStart(builder): + builder.StartObject(2) + + +def FullyConnectedOptionsAddFusedActivationFunction(builder, fusedActivationFunction): + builder.PrependInt8Slot(0, fusedActivationFunction, 0) + + +def FullyConnectedOptionsAddWeightsFormat(builder, weightsFormat): + builder.PrependInt8Slot(1, weightsFormat, 0) + + +def FullyConnectedOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/FullyConnectedOptionsWeightsFormat.py b/tools/tflitefile_tool/tflite/FullyConnectedOptionsWeightsFormat.py new file mode 100644 index 000000000..143fc5122 --- /dev/null +++ b/tools/tflitefile_tool/tflite/FullyConnectedOptionsWeightsFormat.py @@ -0,0 +1,8 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + + +class FullyConnectedOptionsWeightsFormat(object): + DEFAULT = 0 + SHUFFLED4x16INT8 = 1 diff --git a/tools/tflitefile_tool/tflite/GatherOptions.py b/tools/tflitefile_tool/tflite/GatherOptions.py new file mode 100644 index 000000000..cfb54496b --- /dev/null +++ b/tools/tflitefile_tool/tflite/GatherOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class GatherOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsGatherOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = GatherOptions() + x.Init(buf, n + offset) + return x + + # GatherOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # GatherOptions + def Axis(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/GreaterEqualOptions.py b/tools/tflitefile_tool/tflite/GreaterEqualOptions.py new file mode 100644 index 000000000..12df3c88c --- /dev/null +++ b/tools/tflitefile_tool/tflite/GreaterEqualOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class GreaterEqualOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsGreaterEqualOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = GreaterEqualOptions() + x.Init(buf, n + offset) + return x + + # GreaterEqualOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def GreaterEqualOptionsStart(builder): + builder.StartObject(0) + + +def GreaterEqualOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/GreaterOptions.py b/tools/tflitefile_tool/tflite/GreaterOptions.py new file mode 100644 index 000000000..614cdb290 --- /dev/null +++ b/tools/tflitefile_tool/tflite/GreaterOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class GreaterOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsGreaterOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = GreaterOptions() + x.Init(buf, n + offset) + return x + + # GreaterOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def GreaterOptionsStart(builder): + builder.StartObject(0) + + +def GreaterOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/L2NormOptions.py b/tools/tflitefile_tool/tflite/L2NormOptions.py new file mode 100644 index 000000000..1d3ab1ec8 --- /dev/null +++ b/tools/tflitefile_tool/tflite/L2NormOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class L2NormOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsL2NormOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = L2NormOptions() + x.Init(buf, n + offset) + return x + + # L2NormOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # L2NormOptions + def FusedActivationFunction(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/LSHProjectionOptions.py b/tools/tflitefile_tool/tflite/LSHProjectionOptions.py new file mode 100644 index 000000000..055eb75ff --- /dev/null +++ b/tools/tflitefile_tool/tflite/LSHProjectionOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class LSHProjectionOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsLSHProjectionOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = LSHProjectionOptions() + x.Init(buf, n + offset) + return x + + # LSHProjectionOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # LSHProjectionOptions + def Type(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/LSHProjectionType.py b/tools/tflitefile_tool/tflite/LSHProjectionType.py new file mode 100644 index 000000000..328179114 --- /dev/null +++ b/tools/tflitefile_tool/tflite/LSHProjectionType.py @@ -0,0 +1,9 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + + +class LSHProjectionType(object): + UNKNOWN = 0 + SPARSE = 1 + DENSE = 2 diff --git a/tools/tflitefile_tool/tflite/LSTMKernelType.py b/tools/tflitefile_tool/tflite/LSTMKernelType.py new file mode 100644 index 000000000..f0e96f3fc --- /dev/null +++ b/tools/tflitefile_tool/tflite/LSTMKernelType.py @@ -0,0 +1,8 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + + +class LSTMKernelType(object): + FULL = 0 + BASIC = 1 diff --git a/tools/tflitefile_tool/tflite/LSTMOptions.py b/tools/tflitefile_tool/tflite/LSTMOptions.py new file mode 100644 index 000000000..97c5bd8a4 --- /dev/null +++ b/tools/tflitefile_tool/tflite/LSTMOptions.py @@ -0,0 +1,72 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class LSTMOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsLSTMOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = LSTMOptions() + x.Init(buf, n + offset) + return x + + # LSTMOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # LSTMOptions + def FusedActivationFunction(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + # LSTMOptions + def CellClip(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Float32Flags, o + self._tab.Pos) + return 0.0 + + # LSTMOptions + def ProjClip(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Float32Flags, o + self._tab.Pos) + return 0.0 + + # LSTMOptions + def KernelType(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + +def LSTMOptionsStart(builder): + builder.StartObject(4) + + +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 LSTMOptionsAddKernelType(builder, kernelType): + builder.PrependInt8Slot(3, kernelType, 0) + + +def LSTMOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/LessEqualOptions.py b/tools/tflitefile_tool/tflite/LessEqualOptions.py new file mode 100644 index 000000000..ef93bcc9e --- /dev/null +++ b/tools/tflitefile_tool/tflite/LessEqualOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class LessEqualOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsLessEqualOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = LessEqualOptions() + x.Init(buf, n + offset) + return x + + # LessEqualOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def LessEqualOptionsStart(builder): + builder.StartObject(0) + + +def LessEqualOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/LessOptions.py b/tools/tflitefile_tool/tflite/LessOptions.py new file mode 100644 index 000000000..a94b37f17 --- /dev/null +++ b/tools/tflitefile_tool/tflite/LessOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class LessOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsLessOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = LessOptions() + x.Init(buf, n + offset) + return x + + # LessOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def LessOptionsStart(builder): + builder.StartObject(0) + + +def LessOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/LocalResponseNormalizationOptions.py b/tools/tflitefile_tool/tflite/LocalResponseNormalizationOptions.py new file mode 100644 index 000000000..fd9117ac5 --- /dev/null +++ b/tools/tflitefile_tool/tflite/LocalResponseNormalizationOptions.py @@ -0,0 +1,72 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class LocalResponseNormalizationOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsLocalResponseNormalizationOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = LocalResponseNormalizationOptions() + x.Init(buf, n + offset) + return x + + # LocalResponseNormalizationOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # LocalResponseNormalizationOptions + def Radius(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # LocalResponseNormalizationOptions + def Bias(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Float32Flags, o + self._tab.Pos) + return 0.0 + + # LocalResponseNormalizationOptions + def Alpha(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Float32Flags, o + self._tab.Pos) + return 0.0 + + # LocalResponseNormalizationOptions + def Beta(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/LogSoftmaxOptions.py b/tools/tflitefile_tool/tflite/LogSoftmaxOptions.py new file mode 100644 index 000000000..1b059d22f --- /dev/null +++ b/tools/tflitefile_tool/tflite/LogSoftmaxOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class LogSoftmaxOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsLogSoftmaxOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = LogSoftmaxOptions() + x.Init(buf, n + offset) + return x + + # LogSoftmaxOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def LogSoftmaxOptionsStart(builder): + builder.StartObject(0) + + +def LogSoftmaxOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/MaximumMinimumOptions.py b/tools/tflitefile_tool/tflite/MaximumMinimumOptions.py new file mode 100644 index 000000000..c99494be3 --- /dev/null +++ b/tools/tflitefile_tool/tflite/MaximumMinimumOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class MaximumMinimumOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsMaximumMinimumOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = MaximumMinimumOptions() + x.Init(buf, n + offset) + return x + + # MaximumMinimumOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def MaximumMinimumOptionsStart(builder): + builder.StartObject(0) + + +def MaximumMinimumOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/MeanOptions.py b/tools/tflitefile_tool/tflite/MeanOptions.py new file mode 100644 index 000000000..9d49119ac --- /dev/null +++ b/tools/tflitefile_tool/tflite/MeanOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class MeanOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsMeanOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = MeanOptions() + x.Init(buf, n + offset) + return x + + # MeanOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # MeanOptions + def KeepDims(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/Model.py b/tools/tflitefile_tool/tflite/Model.py new file mode 100644 index 000000000..4d1e01f44 --- /dev/null +++ b/tools/tflitefile_tool/tflite/Model.py @@ -0,0 +1,171 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class Model(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsModel(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = Model() + x.Init(buf, n + offset) + return x + + # Model + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # Model + def Version(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos) + return 0 + + # Model + def OperatorCodes(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from .OperatorCode import OperatorCode + obj = OperatorCode() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Model + def OperatorCodesLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Model + def Subgraphs(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from .SubGraph import SubGraph + obj = SubGraph() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Model + def SubgraphsLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Model + def Description(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return "" + + # Model + def Buffers(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from .Buffer import Buffer + obj = Buffer() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Model + def BuffersLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Model + def MetadataBuffer(self, j): + 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.Int32Flags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 4)) + return 0 + + # Model + def MetadataBufferAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Int32Flags, o) + return 0 + + # Model + def MetadataBufferLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + +def ModelStart(builder): + builder.StartObject(6) + + +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 ModelAddMetadataBuffer(builder, metadataBuffer): + builder.PrependUOffsetTRelativeSlot( + 5, flatbuffers.number_types.UOffsetTFlags.py_type(metadataBuffer), 0) + + +def ModelStartMetadataBufferVector(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 new file mode 100644 index 000000000..e15c4d606 --- /dev/null +++ b/tools/tflitefile_tool/tflite/MulOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class MulOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsMulOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = MulOptions() + x.Init(buf, n + offset) + return x + + # MulOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # MulOptions + def FusedActivationFunction(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/NegOptions.py b/tools/tflitefile_tool/tflite/NegOptions.py new file mode 100644 index 000000000..f3d98e782 --- /dev/null +++ b/tools/tflitefile_tool/tflite/NegOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class NegOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsNegOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = NegOptions() + x.Init(buf, n + offset) + return x + + # NegOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def NegOptionsStart(builder): + builder.StartObject(0) + + +def NegOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/NotEqualOptions.py b/tools/tflitefile_tool/tflite/NotEqualOptions.py new file mode 100644 index 000000000..25419ce53 --- /dev/null +++ b/tools/tflitefile_tool/tflite/NotEqualOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class NotEqualOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsNotEqualOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = NotEqualOptions() + x.Init(buf, n + offset) + return x + + # NotEqualOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def NotEqualOptionsStart(builder): + builder.StartObject(0) + + +def NotEqualOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/Operator.py b/tools/tflitefile_tool/tflite/Operator.py new file mode 100644 index 000000000..67cc8f0b5 --- /dev/null +++ b/tools/tflitefile_tool/tflite/Operator.py @@ -0,0 +1,208 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class Operator(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsOperator(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = Operator() + x.Init(buf, n + offset) + return x + + # Operator + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # Operator + def OpcodeIndex(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos) + return 0 + + # Operator + def Inputs(self, j): + 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 0 + + # Operator + def InputsAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Int32Flags, o) + return 0 + + # Operator + def InputsLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Operator + def Outputs(self, j): + 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 0 + + # Operator + def OutputsAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Int32Flags, o) + return 0 + + # Operator + def OutputsLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Operator + def BuiltinOptionsType(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Uint8Flags, o + self._tab.Pos) + return 0 + + # Operator + def BuiltinOptions(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + from flatbuffers.table import Table + obj = Table(bytearray(), 0) + self._tab.Union(obj, o) + return obj + return None + + # Operator + def CustomOptions(self, j): + 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 0 + + # Operator + def CustomOptionsAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Uint8Flags, o) + return 0 + + # Operator + def CustomOptionsLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Operator + def CustomOptionsFormat(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(16)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + # Operator + def MutatingVariableInputs(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18)) + if o != 0: + a = self._tab.Vector(o) + return self._tab.Get( + flatbuffers.number_types.BoolFlags, + a + flatbuffers.number_types.UOffsetTFlags.py_type(j * 1)) + return 0 + + # Operator + def MutatingVariableInputsAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.BoolFlags, o) + return 0 + + # Operator + def MutatingVariableInputsLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(18)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + +def OperatorStart(builder): + builder.StartObject(8) + + +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 OperatorAddMutatingVariableInputs(builder, mutatingVariableInputs): + builder.PrependUOffsetTRelativeSlot( + 7, flatbuffers.number_types.UOffsetTFlags.py_type(mutatingVariableInputs), 0) + + +def OperatorStartMutatingVariableInputsVector(builder, numElems): + return builder.StartVector(1, numElems, 1) + + +def OperatorEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/OperatorCode.py b/tools/tflitefile_tool/tflite/OperatorCode.py new file mode 100644 index 000000000..0f945b901 --- /dev/null +++ b/tools/tflitefile_tool/tflite/OperatorCode.py @@ -0,0 +1,62 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class OperatorCode(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsOperatorCode(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = OperatorCode() + x.Init(buf, n + offset) + return x + + # OperatorCode + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # OperatorCode + def BuiltinCode(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + # OperatorCode + def CustomCode(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return "" + + # OperatorCode + def Version(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 1 + + +def OperatorCodeStart(builder): + builder.StartObject(3) + + +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 OperatorCodeAddVersion(builder, version): + builder.PrependInt32Slot(2, version, 1) + + +def OperatorCodeEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/PadOptions.py b/tools/tflitefile_tool/tflite/PadOptions.py new file mode 100644 index 000000000..46039443c --- /dev/null +++ b/tools/tflitefile_tool/tflite/PadOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class PadOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsPadOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = PadOptions() + x.Init(buf, n + offset) + return x + + # PadOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def PadOptionsStart(builder): + builder.StartObject(0) + + +def PadOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/PadV2Options.py b/tools/tflitefile_tool/tflite/PadV2Options.py new file mode 100644 index 000000000..bddea9d46 --- /dev/null +++ b/tools/tflitefile_tool/tflite/PadV2Options.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class PadV2Options(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsPadV2Options(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = PadV2Options() + x.Init(buf, n + offset) + return x + + # PadV2Options + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def PadV2OptionsStart(builder): + builder.StartObject(0) + + +def PadV2OptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/Padding.py b/tools/tflitefile_tool/tflite/Padding.py new file mode 100644 index 000000000..b8b908c0c --- /dev/null +++ b/tools/tflitefile_tool/tflite/Padding.py @@ -0,0 +1,8 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# 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 new file mode 100644 index 000000000..26e46f243 --- /dev/null +++ b/tools/tflitefile_tool/tflite/Pool2DOptions.py @@ -0,0 +1,94 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class Pool2DOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsPool2DOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = Pool2DOptions() + x.Init(buf, n + offset) + return x + + # Pool2DOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # Pool2DOptions + def Padding(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + # Pool2DOptions + def StrideW(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # Pool2DOptions + def StrideH(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # Pool2DOptions + def FilterWidth(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # Pool2DOptions + def FilterHeight(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # Pool2DOptions + def FusedActivationFunction(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/PowOptions.py b/tools/tflitefile_tool/tflite/PowOptions.py new file mode 100644 index 000000000..8368ac542 --- /dev/null +++ b/tools/tflitefile_tool/tflite/PowOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class PowOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsPowOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = PowOptions() + x.Init(buf, n + offset) + return x + + # PowOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def PowOptionsStart(builder): + builder.StartObject(0) + + +def PowOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/QuantizationParameters.py b/tools/tflitefile_tool/tflite/QuantizationParameters.py new file mode 100644 index 000000000..7d5e53072 --- /dev/null +++ b/tools/tflitefile_tool/tflite/QuantizationParameters.py @@ -0,0 +1,160 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class QuantizationParameters(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsQuantizationParameters(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = QuantizationParameters() + x.Init(buf, n + offset) + return x + + # QuantizationParameters + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # QuantizationParameters + def Min(self, j): + 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 0 + + # QuantizationParameters + def MinAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Float32Flags, o) + return 0 + + # QuantizationParameters + def MinLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # QuantizationParameters + def Max(self, j): + 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 0 + + # QuantizationParameters + def MaxAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Float32Flags, o) + return 0 + + # QuantizationParameters + def MaxLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # QuantizationParameters + def Scale(self, j): + 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 0 + + # QuantizationParameters + def ScaleAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Float32Flags, o) + return 0 + + # QuantizationParameters + def ScaleLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # QuantizationParameters + def ZeroPoint(self, j): + 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 0 + + # QuantizationParameters + def ZeroPointAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Int64Flags, o) + return 0 + + # QuantizationParameters + def ZeroPointLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/RNNOptions.py b/tools/tflitefile_tool/tflite/RNNOptions.py new file mode 100644 index 000000000..508b9c8c9 --- /dev/null +++ b/tools/tflitefile_tool/tflite/RNNOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class RNNOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsRNNOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = RNNOptions() + x.Init(buf, n + offset) + return x + + # RNNOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # RNNOptions + def FusedActivationFunction(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/ReducerOptions.py b/tools/tflitefile_tool/tflite/ReducerOptions.py new file mode 100644 index 000000000..5b6fa1acf --- /dev/null +++ b/tools/tflitefile_tool/tflite/ReducerOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class ReducerOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsReducerOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = ReducerOptions() + x.Init(buf, n + offset) + return x + + # ReducerOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # ReducerOptions + def KeepDims(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos) + return 0 + + +def ReducerOptionsStart(builder): + builder.StartObject(1) + + +def ReducerOptionsAddKeepDims(builder, keepDims): + builder.PrependBoolSlot(0, keepDims, 0) + + +def ReducerOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/ReshapeOptions.py b/tools/tflitefile_tool/tflite/ReshapeOptions.py new file mode 100644 index 000000000..b6b2b3551 --- /dev/null +++ b/tools/tflitefile_tool/tflite/ReshapeOptions.py @@ -0,0 +1,61 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class ReshapeOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsReshapeOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = ReshapeOptions() + x.Init(buf, n + offset) + return x + + # ReshapeOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # ReshapeOptions + def NewShape(self, j): + 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 0 + + # ReshapeOptions + def NewShapeAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Int32Flags, o) + return 0 + + # ReshapeOptions + def NewShapeLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/ResizeBilinearOptions.py b/tools/tflitefile_tool/tflite/ResizeBilinearOptions.py new file mode 100644 index 000000000..66512bb1e --- /dev/null +++ b/tools/tflitefile_tool/tflite/ResizeBilinearOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class ResizeBilinearOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsResizeBilinearOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = ResizeBilinearOptions() + x.Init(buf, n + offset) + return x + + # ResizeBilinearOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # ResizeBilinearOptions + def AlignCorners(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/SVDFOptions.py b/tools/tflitefile_tool/tflite/SVDFOptions.py new file mode 100644 index 000000000..1e65dff4b --- /dev/null +++ b/tools/tflitefile_tool/tflite/SVDFOptions.py @@ -0,0 +1,50 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class SVDFOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsSVDFOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = SVDFOptions() + x.Init(buf, n + offset) + return x + + # SVDFOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # SVDFOptions + def Rank(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # SVDFOptions + def FusedActivationFunction(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/SelectOptions.py b/tools/tflitefile_tool/tflite/SelectOptions.py new file mode 100644 index 000000000..5539a87df --- /dev/null +++ b/tools/tflitefile_tool/tflite/SelectOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class SelectOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsSelectOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = SelectOptions() + x.Init(buf, n + offset) + return x + + # SelectOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def SelectOptionsStart(builder): + builder.StartObject(0) + + +def SelectOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/SequenceRNNOptions.py b/tools/tflitefile_tool/tflite/SequenceRNNOptions.py new file mode 100644 index 000000000..bee7a0fc6 --- /dev/null +++ b/tools/tflitefile_tool/tflite/SequenceRNNOptions.py @@ -0,0 +1,50 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class SequenceRNNOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsSequenceRNNOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = SequenceRNNOptions() + x.Init(buf, n + offset) + return x + + # SequenceRNNOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # SequenceRNNOptions + def TimeMajor(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos) + return 0 + + # SequenceRNNOptions + def FusedActivationFunction(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/ShapeOptions.py b/tools/tflitefile_tool/tflite/ShapeOptions.py new file mode 100644 index 000000000..939e27b88 --- /dev/null +++ b/tools/tflitefile_tool/tflite/ShapeOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class ShapeOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsShapeOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = ShapeOptions() + x.Init(buf, n + offset) + return x + + # ShapeOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # ShapeOptions + def OutType(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + +def ShapeOptionsStart(builder): + builder.StartObject(1) + + +def ShapeOptionsAddOutType(builder, outType): + builder.PrependInt8Slot(0, outType, 0) + + +def ShapeOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/SkipGramOptions.py b/tools/tflitefile_tool/tflite/SkipGramOptions.py new file mode 100644 index 000000000..50738b924 --- /dev/null +++ b/tools/tflitefile_tool/tflite/SkipGramOptions.py @@ -0,0 +1,61 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class SkipGramOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsSkipGramOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = SkipGramOptions() + x.Init(buf, n + offset) + return x + + # SkipGramOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # SkipGramOptions + def NgramSize(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # SkipGramOptions + def MaxSkipSize(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # SkipGramOptions + def IncludeAllNgrams(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/SliceOptions.py b/tools/tflitefile_tool/tflite/SliceOptions.py new file mode 100644 index 000000000..2cce3a00c --- /dev/null +++ b/tools/tflitefile_tool/tflite/SliceOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class SliceOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsSliceOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = SliceOptions() + x.Init(buf, n + offset) + return x + + # SliceOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def SliceOptionsStart(builder): + builder.StartObject(0) + + +def SliceOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/SoftmaxOptions.py b/tools/tflitefile_tool/tflite/SoftmaxOptions.py new file mode 100644 index 000000000..05571f2f5 --- /dev/null +++ b/tools/tflitefile_tool/tflite/SoftmaxOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class SoftmaxOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsSoftmaxOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = SoftmaxOptions() + x.Init(buf, n + offset) + return x + + # SoftmaxOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # SoftmaxOptions + def Beta(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/SpaceToBatchNDOptions.py b/tools/tflitefile_tool/tflite/SpaceToBatchNDOptions.py new file mode 100644 index 000000000..ee31e0d5f --- /dev/null +++ b/tools/tflitefile_tool/tflite/SpaceToBatchNDOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class SpaceToBatchNDOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsSpaceToBatchNDOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = SpaceToBatchNDOptions() + x.Init(buf, n + offset) + return x + + # SpaceToBatchNDOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +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 new file mode 100644 index 000000000..277fa1aa5 --- /dev/null +++ b/tools/tflitefile_tool/tflite/SpaceToDepthOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class SpaceToDepthOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsSpaceToDepthOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = SpaceToDepthOptions() + x.Init(buf, n + offset) + return x + + # SpaceToDepthOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # SpaceToDepthOptions + def BlockSize(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/SparseToDenseOptions.py b/tools/tflitefile_tool/tflite/SparseToDenseOptions.py new file mode 100644 index 000000000..2782ae573 --- /dev/null +++ b/tools/tflitefile_tool/tflite/SparseToDenseOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class SparseToDenseOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsSparseToDenseOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = SparseToDenseOptions() + x.Init(buf, n + offset) + return x + + # SparseToDenseOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # SparseToDenseOptions + def ValidateIndices(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos) + return 0 + + +def SparseToDenseOptionsStart(builder): + builder.StartObject(1) + + +def SparseToDenseOptionsAddValidateIndices(builder, validateIndices): + builder.PrependBoolSlot(0, validateIndices, 0) + + +def SparseToDenseOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/SplitOptions.py b/tools/tflitefile_tool/tflite/SplitOptions.py new file mode 100644 index 000000000..a591e2e1e --- /dev/null +++ b/tools/tflitefile_tool/tflite/SplitOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class SplitOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsSplitOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = SplitOptions() + x.Init(buf, n + offset) + return x + + # SplitOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # SplitOptions + def NumSplits(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/SqueezeOptions.py b/tools/tflitefile_tool/tflite/SqueezeOptions.py new file mode 100644 index 000000000..6881c114a --- /dev/null +++ b/tools/tflitefile_tool/tflite/SqueezeOptions.py @@ -0,0 +1,61 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class SqueezeOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsSqueezeOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = SqueezeOptions() + x.Init(buf, n + offset) + return x + + # SqueezeOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # SqueezeOptions + def SqueezeDims(self, j): + 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 0 + + # SqueezeOptions + def SqueezeDimsAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Int32Flags, o) + return 0 + + # SqueezeOptions + def SqueezeDimsLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/StridedSliceOptions.py b/tools/tflitefile_tool/tflite/StridedSliceOptions.py new file mode 100644 index 000000000..99db0da68 --- /dev/null +++ b/tools/tflitefile_tool/tflite/StridedSliceOptions.py @@ -0,0 +1,83 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class StridedSliceOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsStridedSliceOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = StridedSliceOptions() + x.Init(buf, n + offset) + return x + + # StridedSliceOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # StridedSliceOptions + def BeginMask(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # StridedSliceOptions + def EndMask(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # StridedSliceOptions + def EllipsisMask(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # StridedSliceOptions + def NewAxisMask(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # StridedSliceOptions + def ShrinkAxisMask(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/SubGraph.py b/tools/tflitefile_tool/tflite/SubGraph.py new file mode 100644 index 000000000..c20880a36 --- /dev/null +++ b/tools/tflitefile_tool/tflite/SubGraph.py @@ -0,0 +1,164 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class SubGraph(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsSubGraph(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = SubGraph() + x.Init(buf, n + offset) + return x + + # SubGraph + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # SubGraph + def Tensors(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from .Tensor import Tensor + obj = Tensor() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # SubGraph + def TensorsLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # SubGraph + def Inputs(self, j): + 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 0 + + # SubGraph + def InputsAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Int32Flags, o) + return 0 + + # SubGraph + def InputsLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # SubGraph + def Outputs(self, j): + 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 0 + + # SubGraph + def OutputsAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Int32Flags, o) + return 0 + + # SubGraph + def OutputsLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # SubGraph + def Operators(self, j): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + x = self._tab.Vector(o) + x += flatbuffers.number_types.UOffsetTFlags.py_type(j) * 4 + x = self._tab.Indirect(x) + from .Operator import Operator + obj = Operator() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # SubGraph + def OperatorsLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # SubGraph + def Name(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return "" + + +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 new file mode 100644 index 000000000..29b3dcbfb --- /dev/null +++ b/tools/tflitefile_tool/tflite/SubOptions.py @@ -0,0 +1,39 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class SubOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsSubOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = SubOptions() + x.Init(buf, n + offset) + return x + + # SubOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # SubOptions + def FusedActivationFunction(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + 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() diff --git a/tools/tflitefile_tool/tflite/Tensor.py b/tools/tflitefile_tool/tflite/Tensor.py new file mode 100644 index 000000000..468b120f4 --- /dev/null +++ b/tools/tflitefile_tool/tflite/Tensor.py @@ -0,0 +1,122 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class Tensor(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsTensor(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = Tensor() + x.Init(buf, n + offset) + return x + + # Tensor + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # Tensor + def Shape(self, j): + 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 0 + + # Tensor + def ShapeAsNumpy(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.GetVectorAsNumpy(flatbuffers.number_types.Int32Flags, o) + return 0 + + # Tensor + def ShapeLength(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.VectorLen(o) + return 0 + + # Tensor + def Type(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + # Tensor + def Buffer(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Uint32Flags, o + self._tab.Pos) + return 0 + + # Tensor + def Name(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(10)) + if o != 0: + return self._tab.String(o + self._tab.Pos) + return "" + + # Tensor + def Quantization(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(12)) + if o != 0: + x = self._tab.Indirect(o + self._tab.Pos) + from .QuantizationParameters import QuantizationParameters + obj = QuantizationParameters() + obj.Init(self._tab.Bytes, x) + return obj + return None + + # Tensor + def IsVariable(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(14)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.BoolFlags, o + self._tab.Pos) + return 0 + + +def TensorStart(builder): + builder.StartObject(6) + + +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 TensorAddIsVariable(builder, isVariable): + builder.PrependBoolSlot(5, isVariable, 0) + + +def TensorEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/TensorType.py b/tools/tflitefile_tool/tflite/TensorType.py new file mode 100644 index 000000000..e375c65ee --- /dev/null +++ b/tools/tflitefile_tool/tflite/TensorType.py @@ -0,0 +1,15 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + + +class TensorType(object): + FLOAT32 = 0 + FLOAT16 = 1 + INT32 = 2 + UINT8 = 3 + INT64 = 4 + STRING = 5 + BOOL = 6 + INT16 = 7 + COMPLEX64 = 8 diff --git a/tools/tflitefile_tool/tflite/TileOptions.py b/tools/tflitefile_tool/tflite/TileOptions.py new file mode 100644 index 000000000..59543fc31 --- /dev/null +++ b/tools/tflitefile_tool/tflite/TileOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class TileOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsTileOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = TileOptions() + x.Init(buf, n + offset) + return x + + # TileOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def TileOptionsStart(builder): + builder.StartObject(0) + + +def TileOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/TopKV2Options.py b/tools/tflitefile_tool/tflite/TopKV2Options.py new file mode 100644 index 000000000..004898943 --- /dev/null +++ b/tools/tflitefile_tool/tflite/TopKV2Options.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class TopKV2Options(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsTopKV2Options(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = TopKV2Options() + x.Init(buf, n + offset) + return x + + # TopKV2Options + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def TopKV2OptionsStart(builder): + builder.StartObject(0) + + +def TopKV2OptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/TransposeConvOptions.py b/tools/tflitefile_tool/tflite/TransposeConvOptions.py new file mode 100644 index 000000000..d36a8437e --- /dev/null +++ b/tools/tflitefile_tool/tflite/TransposeConvOptions.py @@ -0,0 +1,61 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class TransposeConvOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsTransposeConvOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = TransposeConvOptions() + x.Init(buf, n + offset) + return x + + # TransposeConvOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + # TransposeConvOptions + def Padding(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(4)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int8Flags, o + self._tab.Pos) + return 0 + + # TransposeConvOptions + def StrideW(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(6)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + # TransposeConvOptions + def StrideH(self): + o = flatbuffers.number_types.UOffsetTFlags.py_type(self._tab.Offset(8)) + if o != 0: + return self._tab.Get(flatbuffers.number_types.Int32Flags, o + self._tab.Pos) + return 0 + + +def TransposeConvOptionsStart(builder): + builder.StartObject(3) + + +def TransposeConvOptionsAddPadding(builder, padding): + builder.PrependInt8Slot(0, padding, 0) + + +def TransposeConvOptionsAddStrideW(builder, strideW): + builder.PrependInt32Slot(1, strideW, 0) + + +def TransposeConvOptionsAddStrideH(builder, strideH): + builder.PrependInt32Slot(2, strideH, 0) + + +def TransposeConvOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/TransposeOptions.py b/tools/tflitefile_tool/tflite/TransposeOptions.py new file mode 100644 index 000000000..b796686dd --- /dev/null +++ b/tools/tflitefile_tool/tflite/TransposeOptions.py @@ -0,0 +1,28 @@ +# automatically generated by the FlatBuffers compiler, do not modify + +# namespace: tflite + +import flatbuffers + + +class TransposeOptions(object): + __slots__ = ['_tab'] + + @classmethod + def GetRootAsTransposeOptions(cls, buf, offset): + n = flatbuffers.encode.Get(flatbuffers.packer.uoffset, buf, offset) + x = TransposeOptions() + x.Init(buf, n + offset) + return x + + # TransposeOptions + def Init(self, buf, pos): + self._tab = flatbuffers.table.Table(buf, pos) + + +def TransposeOptionsStart(builder): + builder.StartObject(0) + + +def TransposeOptionsEnd(builder): + return builder.EndObject() diff --git a/tools/tflitefile_tool/tflite/__init__.py b/tools/tflitefile_tool/tflite/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tools/tflitefile_tool/tflite/__init__.py |