From 9f54a8a083fc6ac1144bc1b9b4c68a6417ab4e87 Mon Sep 17 00:00:00 2001 From: Pavel Iliutchenko/AI Tools Lab /SRR/Engineer/Samsung Electronics Date: Thu, 7 Nov 2019 16:13:17 +0300 Subject: [PATCH] [mir-tflite-importer] TFLite frontend schema upgrade (#8789) * Upgraded tflite importer schema Signed-off-by: Pavel Iliutchenko --- compiler/mir-tflite-importer/schema/schema.fbs | 151 +++++++++++++++++++++++- compiler/mir-tflite-importer/schema/schema.meta | 2 +- 2 files changed, 148 insertions(+), 5 deletions(-) diff --git a/compiler/mir-tflite-importer/schema/schema.fbs b/compiler/mir-tflite-importer/schema/schema.fbs index 3ece383..288b8bc 100644 --- a/compiler/mir-tflite-importer/schema/schema.fbs +++ b/compiler/mir-tflite-importer/schema/schema.fbs @@ -64,9 +64,20 @@ table QuantizationParameters { scale:[float]; // For dequantizing the tensor's values. zero_point:[long]; - // If this is not none, the quantization parameters above are ignored and the - // value of the QuantizationDetails union below should be used. + // If this is not none, the other quantization parameters (i.e. min, max, + // scale, zero_point fields above) are ignored and the value of the + // QuantizationDetails union should be used. details:QuantizationDetails; + + // Specifies the dimension of the Tensor's shape that the scales and + // zero_points correspond to. For example, a tensor t, with dims=[4, 3, 2, 1] + // with quantization params: + // scale=[1.0, 2.0, 3.0], zero_point=[1, 2, 3], quantization_dimension=1 + // will be quantized across the second dimension of t. + // t[:, 0, :, :] will have scale[0]=1.0, zero_point[0]=1 + // t[:, 1, :, :] will have scale[1]=2.0, zero_point[0]=2 + // t[:, 2, :, :] will have scale[2]=3.0, zero_point[0]=3 + quantized_dimension:int; } table Tensor { @@ -100,7 +111,7 @@ enum BuiltinOperator : byte { CONCATENATION = 2, CONV_2D = 3, DEPTHWISE_CONV_2D = 4, - // DEPTH_TO_SPACE = 5, + DEPTH_TO_SPACE = 5, DEQUANTIZE = 6, EMBEDDING_LOOKUP = 7, FLOOR = 8, @@ -205,6 +216,26 @@ enum BuiltinOperator : byte { MIRROR_PAD = 100, ABS = 101, SPLIT_V = 102, + UNIQUE = 103, + CEIL = 104, + REVERSE_V2 = 105, + ADD_N = 106, + GATHER_ND = 107, + COS = 108, + WHERE = 109, + RANK = 110, + ELU = 111, + REVERSE_SEQUENCE = 112, + MATRIX_DIAG = 113, + QUANTIZE = 114, + MATRIX_SET_DIAG = 115, + ROUND = 116, + HARD_SWISH = 117, + IF = 118, + WHILE = 119, + NON_MAX_SUPPRESSION_V4 = 120, + NON_MAX_SUPPRESSION_V5 = 121, + SCATTER_ND = 122 } // Options for the builtin operators. @@ -288,6 +319,24 @@ union BuiltinOptions { MirrorPadOptions, AbsOptions, SplitVOptions, + UniqueOptions, + ReverseV2Options, + AddNOptions, + GatherNdOptions, + CosOptions, + WhereOptions, + RankOptions, + ReverseSequenceOptions, + MatrixDiagOptions, + QuantizeOptions, + MatrixSetDiagOptions, + HardSwishOptions, + IfOptions, + WhileOptions, + DepthToSpaceOptions, + NonMaxSuppressionV4Options, + NonMaxSuppressionV5Options, + ScatterNdOptions } enum Padding : byte { SAME, VALID } @@ -382,6 +431,11 @@ table FullyConnectedOptions { // Parameters for FullyConnected version 2 or above. weights_format:FullyConnectedOptionsWeightsFormat = DEFAULT; + + // Parameters for FullyConnected version 5 or above. + // If set to true, then the number of dimension is preserved. Furthermore, + // all but the last dimension of the input and output shapes will be equal. + keep_num_dims: bool; } table SoftmaxOptions { @@ -443,12 +497,19 @@ table UnidirectionalSequenceLSTMOptions { } table BidirectionalSequenceLSTMOptions { + // Parameters supported by version 1: fused_activation_function:ActivationFunctionType; cell_clip: float; // Optional, 0.0 means no clipping proj_clip: float; // Optional, 0.0 means no clipping // If true, store the outputs of both directions into the first output. merge_outputs: bool; + + // Parameters supported by version 2: + // If true then first dimension is sequence, otherwise batch. + // Version 1 implementations assumed time_major to be true, so this default + // value should never change. + time_major: bool = true; } table ResizeBilinearOptions { @@ -493,6 +554,10 @@ table SpaceToDepthOptions { block_size: int; } +table DepthToSpaceOptions { + block_size: int; +} + table SubOptions { fused_activation_function:ActivationFunctionType; } @@ -524,6 +589,9 @@ table TransposeOptions { table ExpOptions { } +table CosOptions { +} + table ReducerOptions { keep_dims: bool; } @@ -618,6 +686,9 @@ table ShapeOptions { out_type : TensorType; } +table RankOptions { +} + table PowOptions { } @@ -647,6 +718,9 @@ table AbsOptions { } +table HardSwishOptions { +} + table LogicalAndOptions { } @@ -694,6 +768,55 @@ table MirrorPadOptions { mode:MirrorPadMode; } +table UniqueOptions { + idx_out_type:TensorType = INT32; +} + +table ReverseV2Options { +} + +table AddNOptions { +} + +table GatherNdOptions { +} + +table WhereOptions { +} + +table ReverseSequenceOptions { + seq_dim:int; + batch_dim:int = 0; +} + +table MatrixDiagOptions { +} + +table QuantizeOptions { +} + +table MatrixSetDiagOptions { +} + +table IfOptions { + then_subgraph_index:int; + else_subgraph_index:int; +} + +table WhileOptions { + cond_subgraph_index:int; + body_subgraph_index:int; +} + +table NonMaxSuppressionV4Options { +} + +table NonMaxSuppressionV5Options { +} + +table ScatterNdOptions { +} + // An OperatorCode can be an enum value (BuiltinOperator) if the operator is a // builtin, or a string if the operator is custom. table OperatorCode { @@ -735,6 +858,15 @@ table Operator { // If the list is empty, no variable is mutated in this operator. // The list either has the same length as `inputs`, or is empty. mutating_variable_inputs:[bool]; + + // A list of indices to the subgraph's "tensors" that are internal to an Op. + // Internal tensors are those that do not flow in or out of the operation, + // but instead are part of internal computation. As such, the operation's + // implementation may manage its memory more efficiently. They are needed + // however (i.e. not just an implementation detail) since they are part of the + // computation, which may require relevant metadata such as quantization + // parameters. + intermediates:[int]; } // The root type, defining a subgraph, which typically represents an entire @@ -765,6 +897,13 @@ table Buffer { data:[ubyte] (force_align: 16); } +table Metadata { + // A human readable string to uniquely identify a Metadata. + name:string; + // An index to the buffers table. + buffer:uint; +} + table Model { // Version of the schema. version:uint; @@ -787,8 +926,12 @@ table Model { // their buffer. buffers:[Buffer]; - // Metadata about the model. Indirects into the existings buffers list. + // Metadata about the model. Indirects into the existings buffers list. + // Deprecated, prefer to use metadata field. metadata_buffer:[int]; + + // Metadata about the model. + metadata:[Metadata]; } root_type Model; \ No newline at end of file diff --git a/compiler/mir-tflite-importer/schema/schema.meta b/compiler/mir-tflite-importer/schema/schema.meta index 72f9afd..c86134c 100644 --- a/compiler/mir-tflite-importer/schema/schema.meta +++ b/compiler/mir-tflite-importer/schema/schema.meta @@ -1,2 +1,2 @@ REPO=https://github.com/tensorflow/tensorflow.git -COMMIT=49123b0 +COMMIT=998eadd -- 2.7.4