Imported Upstream version 1.18.0
[platform/core/ml/nnfw.git] / res / TensorFlowLiteSchema / 2.6.0 / schema.fbs
1 // Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Revision History
16 // Version 0: Initial version.
17 // Version 1: Add subgraphs to schema.
18 // Version 2: Rename operators to conform to NN API.
19 // Version 3: Move buffer data from Model.Subgraph.Tensors to Model.Buffers.
20 // Version 3a: Add new builtin op code field. Has backward compatibility with
21 //             version 3.
22
23 namespace tflite;
24
25 // This corresponds to the version.
26 file_identifier "TFL3";
27 // File extension of any written files.
28 file_extension "tflite";
29
30 // IMPORTANT: All new members of tables, enums and unions must be added at the
31 // end to ensure backwards compatibility.
32
33 // The type of data stored in a tensor.
34 enum TensorType : byte {
35   FLOAT32 = 0,
36   FLOAT16 = 1,
37   INT32 = 2,
38   UINT8 = 3,
39   INT64 = 4,
40   STRING = 5,
41   BOOL = 6,
42   INT16 = 7,
43   COMPLEX64 = 8,
44   INT8 = 9,
45   FLOAT64 = 10,
46   COMPLEX128 = 11,
47   UINT64 = 12,
48   // Experimental: Resource and variant types are experimental, that are subject
49   // to change. Do not implement custom kernels using resource & variant types
50   // now.
51   RESOURCE = 13,
52   VARIANT = 14,
53   UINT32 = 15,
54 }
55
56 // Custom quantization parameters for experimenting with new quantization
57 // techniques.
58 table CustomQuantization {
59   custom:[ubyte] (force_align: 16);
60 }
61
62 // Represents a specific quantization technique's parameters.
63 union QuantizationDetails {
64   CustomQuantization,
65 }
66
67 // Parameters for converting a quantized tensor back to float.
68 table QuantizationParameters {
69   // These four parameters are the asymmetric linear quantization parameters.
70   // Given a quantized value q, the corresponding float value f should be:
71   //   f = scale * (q - zero_point)
72   // For other quantization types, the QuantizationDetails below is used.
73   min:[float];  // For importing back into tensorflow.
74   max:[float];  // For importing back into tensorflow.
75   scale:[float];  // For dequantizing the tensor's values.
76   zero_point:[long];
77
78   // If this is not none, the other quantization parameters (i.e. min, max,
79   // scale, zero_point fields above) are ignored and the value of the
80   // QuantizationDetails union should be used.
81   details:QuantizationDetails;
82
83   // Specifies the dimension of the Tensor's shape that the scales and
84   // zero_points correspond to. For example, a tensor t, with dims=[4, 3, 2, 1]
85   // with quantization params:
86   //   scale=[1.0, 2.0, 3.0], zero_point=[1, 2, 3], quantization_dimension=1
87   // will be quantized across the second dimension of t.
88   //   t[:, 0, :, :] will have scale[0]=1.0, zero_point[0]=1
89   //   t[:, 1, :, :] will have scale[1]=2.0, zero_point[0]=2
90   //   t[:, 2, :, :] will have scale[2]=3.0, zero_point[0]=3
91   quantized_dimension:int;
92 }
93
94 // Sparse tensors.
95 // We use a modification of the TACO format.
96 // Reference: http://tensor-compiler.org/kjolstad-oopsla17-tensor-compiler.pdf
97 //
98 // To encode a conceptual n-dimensional dense tensor with dims (d0, ..., dn-1),
99 // potentially with a k-dimensional block (0 <= k <= n) with dims
100 // (dn, ..., dn+k-1), the format needs to specify:
101 //   1. In what order to traverse these dimensions. For example, to store a 2-D
102 //      matrix in row major order, the traversal order would be (d0, d1),
103 //      whereas to store it in column major order, the traversal order would be
104 //      (d1, d0). If the 2-D matrix has a 2-D inner block, the traversal order
105 //      could be (d0, d1, d2, d3).
106 //   2. How each block dimension in (dn, ..., dn+k-1) maps to the original
107 //      tensor dimension in (d0, ..., dn-1).
108 //   3. In the traversal order defined above, the format (dense vs. sparse) and
109 //      index metadata for each dimension. For a dense dimension, this is just
110 //      the size of that dimension. For a sparse dimension, it's the same as
111 //      the compressed index defined in the Compressed Sparse Row (CSR) format.
112 //      (http://scipy-lectures.org/advanced/scipy_sparse/csr_matrix.html)
113
114 // The storage type for a dimension. Currently we support:
115 //   1. DENSE: each coordinate in this dimension is stored implicitly.
116 //   2. SPARSE_CSR: only the coordinates with non-zero elements are stored. The
117 //      compression technique is the same what CSR uses.
118 // More types like a sparse dimension with a different compression technique
119 // could be added to the list in the future.
120 enum DimensionType : byte {
121   DENSE = 0,
122   SPARSE_CSR = 1,
123 }
124
125 table Int32Vector {
126   values:[int];
127 }
128
129 table Uint16Vector {
130   values:[ushort] (force_align: 4);
131 }
132
133 table Uint8Vector {
134   values:[ubyte] (force_align: 4);
135 }
136
137 // Variable-typed buffer to store the index metadata for a sparse dimension.
138 // The widest type is Int32 instead of UInt32 because tensor's shape is a int32
139 // vector. We don't want the per-dimensional index to overflow that range.
140 union SparseIndexVector {
141   Int32Vector,
142   Uint16Vector,
143   Uint8Vector
144 }
145
146 table DimensionMetadata {
147   // Whether a dimension is dense or sparse.
148   format:DimensionType;
149   // Index metadata used for a dimension.
150   //   - If format is DimensionType.DENSE then we use the dense_size field to
151   //     store the size of that dimension. Each index in that dimension is
152   //     stored implicitly.
153   //   - If format is DimensionType.SPARSE_CSR then we use array_segments and
154   //     array_indices to encode that dimension. array_segments represents how
155   //     to segment the indices array, each segment corresponds to one element
156   //     in the previous dimension. array_indices represents the index of the
157   //     non-zero elements within this dimension (as those in the CSR matrix
158   //     format, where the first array is row pointers and the second array is
159   //     column indices).
160   dense_size:int;
161   array_segments:SparseIndexVector;
162   array_indices:SparseIndexVector;
163 }
164
165 // Parameters to encode a sparse TfLite tensor.
166 table SparsityParameters {
167   // The traversal order of the dimensions defined in the `shape` field of the
168   // conceptual dense tensor. For a n-dimensional tensors with dims (d0, d1,
169   // ..., dn-1),
170   //   - if not block sparse, the traversal_order is just a permutation of (d0,
171   //     ..., dn-1). For example, a 2-D matrix stored in row-major order would
172   //     have traversal_order = (d0, d1).
173   //   - if block sparse with a k-dimensional block (0 <= k <= n), the
174   //     traversal_order has n + k elements. The first n elements are still a
175   //     permutation of (d0, ..., dn-1). The lask k elements are a permutation
176   //     of (dn, ..., dn+k-1), defining how to traverse a block internally. For
177   //     example, a 2-D matrix with 2-D blocks, both stored in row-major order
178   //     would have traversal_order = (d0, d1, d2, d3).
179   traversal_order:[int];
180   // For an n-dimensional tensor with a k-dimensional block (0 <= k <= n),
181   // stores how a block dimension in (dn, ..., dn+k-1) maps to the original
182   // tensor dimension in (d0, ..., dn).
183   // It's stored in the order of (dn, ..., dn+k-1).
184   // If not block-sparse, this field is NULL.
185   block_map:[int];
186   // In the traversal order defined above, the metadata needed for
187   // each dimension to locate the non-zero values in the original dense tensor.
188   // The size of the dim_metadata array = the size of the traversal_order array
189   // = n + k.
190   dim_metadata:[DimensionMetadata];
191 }
192
193 table Tensor {
194   // The tensor shape. The meaning of each entry is operator-specific but
195   // builtin ops use: [batch size, height, width, number of channels] (That's
196   // Tensorflow's NHWC).
197   shape:[int];
198   type:TensorType;
199   // An index that refers to the buffers table at the root of the model. Or,
200   // if there is no data buffer associated (i.e. intermediate results), then
201   // this is 0 (which refers to an always existent empty buffer).
202   //
203   // The data_buffer itself is an opaque container, with the assumption that the
204   // target device is little-endian. In addition, all builtin operators assume
205   // the memory is ordered such that if `shape` is [4, 3, 2], then index
206   // [i, j, k] maps to data_buffer[i*3*2 + j*2 + k].
207   buffer:uint;
208   name:string;  // For debugging and importing back into tensorflow.
209   quantization:QuantizationParameters;  // Optional.
210
211   is_variable:bool = false;
212
213   // Parameters to encode a sparse tensor. See the example in
214   // tensorflow/lite/testdata/sparse_tensor.json.
215   sparsity:SparsityParameters;  // Optional.
216
217   // Encodes `shape` with unknown dimensions. Unknown dimensions are
218   // represented with -1.
219   shape_signature:[int]; // Optional.
220 }
221
222 // A list of builtin operators. Builtin operators are slightly faster than custom
223 // ones, but not by much. Moreover, while custom operators accept an opaque
224 // object containing configuration parameters, builtins have a predetermined
225 // set of acceptable options.
226 // LINT.IfChange
227 enum BuiltinOperator : int32 {
228   ADD = 0,
229   AVERAGE_POOL_2D = 1,
230   CONCATENATION = 2,
231   CONV_2D = 3,
232   DEPTHWISE_CONV_2D = 4,
233   DEPTH_TO_SPACE = 5,
234   DEQUANTIZE = 6,
235   EMBEDDING_LOOKUP = 7,
236   FLOOR = 8,
237   FULLY_CONNECTED = 9,
238   HASHTABLE_LOOKUP = 10,
239   L2_NORMALIZATION = 11,
240   L2_POOL_2D = 12,
241   LOCAL_RESPONSE_NORMALIZATION = 13,
242   LOGISTIC = 14,
243   LSH_PROJECTION = 15,
244   LSTM = 16,
245   MAX_POOL_2D = 17,
246   MUL = 18,
247   RELU = 19,
248   // NOTE(aselle): RELU_N1_TO_1 used to be called RELU1, but it was renamed
249   // since different model developers use RELU1 in different ways. Never
250   // create another op called RELU1.
251   RELU_N1_TO_1 = 20,
252   RELU6 = 21,
253   RESHAPE = 22,
254   RESIZE_BILINEAR = 23,
255   RNN = 24,
256   SOFTMAX = 25,
257   SPACE_TO_DEPTH = 26,
258   SVDF = 27,
259   TANH = 28,
260   CONCAT_EMBEDDINGS = 29,
261   SKIP_GRAM = 30,
262   CALL = 31,
263   CUSTOM = 32,
264   EMBEDDING_LOOKUP_SPARSE = 33,
265   PAD = 34,
266   UNIDIRECTIONAL_SEQUENCE_RNN = 35,
267   GATHER = 36,
268   BATCH_TO_SPACE_ND = 37,
269   SPACE_TO_BATCH_ND = 38,
270   TRANSPOSE = 39,
271   MEAN = 40,
272   SUB = 41,
273   DIV = 42,
274   SQUEEZE = 43,
275   UNIDIRECTIONAL_SEQUENCE_LSTM = 44,
276   STRIDED_SLICE = 45,
277   BIDIRECTIONAL_SEQUENCE_RNN = 46,
278   EXP = 47,
279   TOPK_V2 = 48,
280   SPLIT = 49,
281   LOG_SOFTMAX = 50,
282   // DELEGATE is a special op type for the operations which are delegated to
283   // other backends.
284   // WARNING: Experimental interface, subject to change
285   DELEGATE = 51,
286   BIDIRECTIONAL_SEQUENCE_LSTM = 52,
287   CAST = 53,
288   PRELU = 54,
289   MAXIMUM = 55,
290   ARG_MAX = 56,
291   MINIMUM = 57,
292   LESS = 58,
293   NEG = 59,
294   PADV2 = 60,
295   GREATER = 61,
296   GREATER_EQUAL = 62,
297   LESS_EQUAL = 63,
298   SELECT = 64,
299   SLICE = 65,
300   SIN = 66,
301   TRANSPOSE_CONV = 67,
302   SPARSE_TO_DENSE = 68,
303   TILE = 69,
304   EXPAND_DIMS = 70,
305   EQUAL = 71,
306   NOT_EQUAL = 72,
307   LOG = 73,
308   SUM = 74,
309   SQRT = 75,
310   RSQRT = 76,
311   SHAPE = 77,
312   POW = 78,
313   ARG_MIN = 79,
314   FAKE_QUANT = 80,
315   REDUCE_PROD = 81,
316   REDUCE_MAX = 82,
317   PACK = 83,
318   LOGICAL_OR = 84,
319   ONE_HOT = 85,
320   LOGICAL_AND = 86,
321   LOGICAL_NOT = 87,
322   UNPACK = 88,
323   REDUCE_MIN = 89,
324   FLOOR_DIV = 90,
325   REDUCE_ANY = 91,
326   SQUARE = 92,
327   ZEROS_LIKE = 93,
328   FILL = 94,
329   FLOOR_MOD = 95,
330   RANGE = 96,
331   RESIZE_NEAREST_NEIGHBOR = 97,
332   LEAKY_RELU = 98,
333   SQUARED_DIFFERENCE = 99,
334   MIRROR_PAD = 100,
335   ABS = 101,
336   SPLIT_V = 102,
337   UNIQUE = 103,
338   CEIL = 104,
339   REVERSE_V2 = 105,
340   ADD_N = 106,
341   GATHER_ND = 107,
342   COS = 108,
343   WHERE = 109,
344   RANK = 110,
345   ELU = 111,
346   REVERSE_SEQUENCE = 112,
347   MATRIX_DIAG = 113,
348   QUANTIZE = 114,
349   MATRIX_SET_DIAG = 115,
350   ROUND = 116,
351   HARD_SWISH = 117,
352   IF = 118,
353   WHILE = 119,
354   NON_MAX_SUPPRESSION_V4 = 120,
355   NON_MAX_SUPPRESSION_V5 = 121,
356   SCATTER_ND = 122,
357   SELECT_V2 = 123,
358   DENSIFY = 124,
359   SEGMENT_SUM = 125,
360   BATCH_MATMUL = 126,
361   PLACEHOLDER_FOR_GREATER_OP_CODES = 127,
362   CUMSUM = 128,
363   CALL_ONCE = 129,
364   BROADCAST_TO = 130,
365   RFFT2D = 131,
366   CONV_3D = 132,
367   IMAG=133,
368   REAL=134,
369   COMPLEX_ABS=135,
370   HASHTABLE = 136,
371   HASHTABLE_FIND = 137,
372   HASHTABLE_IMPORT = 138,
373   HASHTABLE_SIZE = 139,
374   REDUCE_ALL = 140,
375   CONV_3D_TRANSPOSE = 141,
376   VAR_HANDLE = 142,
377   READ_VARIABLE = 143,
378   ASSIGN_VARIABLE = 144,
379 }
380 // LINT.ThenChange(nnapi_linter/linter.proto)
381
382 // Options for the builtin operators.
383 union BuiltinOptions {
384   Conv2DOptions,
385   DepthwiseConv2DOptions,
386   ConcatEmbeddingsOptions,
387   LSHProjectionOptions,
388   Pool2DOptions,
389   SVDFOptions,
390   RNNOptions,
391   FullyConnectedOptions,
392   SoftmaxOptions,
393   ConcatenationOptions,
394   AddOptions,
395   L2NormOptions,
396   LocalResponseNormalizationOptions,
397   LSTMOptions,
398   ResizeBilinearOptions,
399   CallOptions,
400   ReshapeOptions,
401   SkipGramOptions,
402   SpaceToDepthOptions,
403   EmbeddingLookupSparseOptions,
404   MulOptions,
405   PadOptions,
406   GatherOptions,
407   BatchToSpaceNDOptions,
408   SpaceToBatchNDOptions,
409   TransposeOptions,
410   ReducerOptions,
411   SubOptions,
412   DivOptions,
413   SqueezeOptions,
414   SequenceRNNOptions,
415   StridedSliceOptions,
416   ExpOptions,
417   TopKV2Options,
418   SplitOptions,
419   LogSoftmaxOptions,
420   CastOptions,
421   DequantizeOptions,
422   MaximumMinimumOptions,
423   ArgMaxOptions,
424   LessOptions,
425   NegOptions,
426   PadV2Options,
427   GreaterOptions,
428   GreaterEqualOptions,
429   LessEqualOptions,
430   SelectOptions,
431   SliceOptions,
432   TransposeConvOptions,
433   SparseToDenseOptions,
434   TileOptions,
435   ExpandDimsOptions,
436   EqualOptions,
437   NotEqualOptions,
438   ShapeOptions,
439   PowOptions,
440   ArgMinOptions,
441   FakeQuantOptions,
442   PackOptions,
443   LogicalOrOptions,
444   OneHotOptions,
445   LogicalAndOptions,
446   LogicalNotOptions,
447   UnpackOptions,
448   FloorDivOptions,
449   SquareOptions,
450   ZerosLikeOptions,
451   FillOptions,
452   BidirectionalSequenceLSTMOptions,
453   BidirectionalSequenceRNNOptions,
454   UnidirectionalSequenceLSTMOptions,
455   FloorModOptions,
456   RangeOptions,
457   ResizeNearestNeighborOptions,
458   LeakyReluOptions,
459   SquaredDifferenceOptions,
460   MirrorPadOptions,
461   AbsOptions,
462   SplitVOptions,
463   UniqueOptions,
464   ReverseV2Options,
465   AddNOptions,
466   GatherNdOptions,
467   CosOptions,
468   WhereOptions,
469   RankOptions,
470   ReverseSequenceOptions,
471   MatrixDiagOptions,
472   QuantizeOptions,
473   MatrixSetDiagOptions,
474   HardSwishOptions,
475   IfOptions,
476   WhileOptions,
477   DepthToSpaceOptions,
478   NonMaxSuppressionV4Options,
479   NonMaxSuppressionV5Options,
480   ScatterNdOptions,
481   SelectV2Options,
482   DensifyOptions,
483   SegmentSumOptions,
484   BatchMatMulOptions,
485   CumsumOptions,
486   CallOnceOptions,
487   BroadcastToOptions,
488   Rfft2dOptions,
489   Conv3DOptions,
490   HashtableOptions,
491   HashtableFindOptions,
492   HashtableImportOptions,
493   HashtableSizeOptions,
494   VarHandleOptions,
495   ReadVariableOptions,
496   AssignVariableOptions,
497 }
498
499 enum Padding : byte { SAME, VALID }
500
501 enum ActivationFunctionType : byte {
502   NONE = 0,
503   RELU = 1,
504   RELU_N1_TO_1 = 2,
505   RELU6 = 3,
506   TANH = 4,
507   SIGN_BIT = 5,
508 }
509
510 table Conv2DOptions {
511   padding:Padding;
512   stride_w:int;
513   stride_h:int;
514   fused_activation_function:ActivationFunctionType;
515   dilation_w_factor:int = 1;
516   dilation_h_factor:int = 1;
517 }
518
519 // Options for both Conv3D and Conv3DTranspose.
520 table Conv3DOptions {
521   padding:Padding;
522   stride_d:int;
523   stride_w:int;
524   stride_h:int;
525   fused_activation_function:ActivationFunctionType;
526   dilation_d_factor:int = 1;
527   dilation_w_factor:int = 1;
528   dilation_h_factor:int = 1;
529 }
530
531 table Pool2DOptions {
532   padding:Padding;
533   stride_w:int;
534   stride_h:int;
535   filter_width:int;
536   filter_height:int;
537   fused_activation_function:ActivationFunctionType;
538 }
539
540 table DepthwiseConv2DOptions {
541   // Parameters for DepthwiseConv version 1 or above.
542   padding:Padding;
543   stride_w:int;
544   stride_h:int;
545   // `depth_multiplier` is redundant. It's used by CPU kernels in
546   // TensorFlow 2.0 or below, but ignored in versions above.
547   // See comments in lite/c/builtin_op_data.h for more details.
548   depth_multiplier:int;
549   fused_activation_function:ActivationFunctionType;
550   // Parameters for DepthwiseConv version 2 or above.
551   dilation_w_factor:int = 1;
552   dilation_h_factor:int = 1;
553 }
554
555 table ConcatEmbeddingsOptions {
556   num_channels:int;
557   num_columns_per_channel:[int];
558   embedding_dim_per_channel:[int]; // This could be inferred from parameters.
559 }
560
561 enum LSHProjectionType: byte {
562   UNKNOWN = 0,
563   SPARSE = 1,
564   DENSE = 2,
565 }
566
567 table LSHProjectionOptions {
568   type: LSHProjectionType;
569 }
570
571 table SVDFOptions {
572   rank:int;
573   fused_activation_function:ActivationFunctionType;
574   // For weights-only quantization, use asymmetric quantization for non
575   // constant inputs at evaluation time.
576   asymmetric_quantize_inputs:bool;
577 }
578
579 // An implementation of TensorFlow RNNCell.
580 table RNNOptions {
581   fused_activation_function:ActivationFunctionType;
582   asymmetric_quantize_inputs:bool;
583 }
584
585 // An implementation of TensorFlow dynamic_rnn with RNNCell.
586 table SequenceRNNOptions {
587   time_major:bool;
588   fused_activation_function:ActivationFunctionType;
589   asymmetric_quantize_inputs:bool;
590 }
591
592 // An implementation of TensorFlow bidrectional_dynamic_rnn with RNNCell.
593 table BidirectionalSequenceRNNOptions {
594   time_major:bool;
595   fused_activation_function:ActivationFunctionType;
596   merge_outputs: bool;
597   asymmetric_quantize_inputs:bool;
598 }
599
600 enum FullyConnectedOptionsWeightsFormat: byte {
601   DEFAULT = 0,
602   SHUFFLED4x16INT8 = 1,
603 }
604
605 // An implementation of TensorFlow fully_connected (a.k.a Dense) layer.
606 table FullyConnectedOptions {
607   // Parameters for FullyConnected version 1 or above.
608   fused_activation_function:ActivationFunctionType;
609
610   // Parameters for FullyConnected version 2 or above.
611   weights_format:FullyConnectedOptionsWeightsFormat = DEFAULT;
612
613   // Parameters for FullyConnected version 5 or above.
614   // If set to true, then the number of dimension is preserved. Furthermore,
615   // all but the last dimension of the input and output shapes will be equal.
616   keep_num_dims: bool;
617
618   // Parameters for FullyConnected version 7 or above.
619   // If set to true, then weights-only op will use asymmetric quantization for
620   // inputs.
621   asymmetric_quantize_inputs: bool;
622 }
623
624 table SoftmaxOptions {
625   beta: float;
626 }
627
628 // An implementation of TensorFlow concat.
629 table ConcatenationOptions {
630   axis:int;
631   fused_activation_function:ActivationFunctionType;
632 }
633
634 table AddOptions {
635   fused_activation_function:ActivationFunctionType;
636   // Parameters supported by version 3.
637   pot_scale_int16:bool = true;
638 }
639
640 table MulOptions {
641   fused_activation_function:ActivationFunctionType;
642 }
643
644 table L2NormOptions {
645   // This field is currently ignored in the L2 Norm Op.
646   fused_activation_function:ActivationFunctionType;
647 }
648
649 table LocalResponseNormalizationOptions {
650   radius:int;
651   bias:float;
652   alpha:float;
653   beta:float;
654 }
655
656 enum LSTMKernelType : byte {
657   // Full LSTM kernel which supports peephole and projection.
658   FULL = 0,
659   // Basic LSTM kernels. Equivalent to TensorFlow BasicLSTMCell.
660   BASIC = 1,
661 }
662
663 // An implementation of TensorFlow LSTMCell and CoupledInputForgetGateLSTMCell
664 table LSTMOptions {
665   // Parameters for LSTM version 1 or above.
666   fused_activation_function:ActivationFunctionType;
667   cell_clip: float; // Optional, 0.0 means no clipping
668   proj_clip: float; // Optional, 0.0 means no clipping
669
670   // Parameters for LSTM version 2 or above.
671   // Basic kernel is only supported in version 2 or above.
672   kernel_type: LSTMKernelType = FULL;
673
674   // Parameters for LSTM version 4 or above.
675   asymmetric_quantize_inputs: bool;
676 }
677
678 // An implementation of TensorFlow dynamic_rnn with LSTMCell.
679 table UnidirectionalSequenceLSTMOptions {
680   fused_activation_function:ActivationFunctionType;
681   cell_clip: float; // Optional, 0.0 means no clipping
682   proj_clip: float; // Optional, 0.0 means no clipping
683
684   // If true then first dimension is sequence, otherwise batch.
685   time_major:bool;
686
687   // Parameter for Unidirectional Sequence LSTM version 4.
688   asymmetric_quantize_inputs:bool;
689 }
690
691 table BidirectionalSequenceLSTMOptions {
692   // Parameters supported by version 1:
693   fused_activation_function:ActivationFunctionType;
694   cell_clip: float; // Optional, 0.0 means no clipping
695   proj_clip: float; // Optional, 0.0 means no clipping
696
697   // If true, store the outputs of both directions into the first output.
698   merge_outputs: bool;
699
700   // Parameters supported by version 2:
701   // If true then first dimension is sequence, otherwise batch.
702   // Version 1 implementations assumed time_major to be true, so this default
703   // value should never change.
704   time_major: bool = true;
705
706   // Parameters for version 3 or above.
707   asymmetric_quantize_inputs:bool;
708 }
709
710 table ResizeBilinearOptions {
711   new_height: int (deprecated);
712   new_width: int (deprecated);
713   align_corners: bool;
714   half_pixel_centers: bool;
715 }
716
717 table ResizeNearestNeighborOptions {
718   align_corners: bool;
719   half_pixel_centers: bool;
720 }
721
722 // A call operation options
723 table CallOptions {
724   // The subgraph index that needs to be called.
725   subgraph:uint;
726 }
727
728 table PadOptions {
729 }
730
731 table PadV2Options {
732 }
733
734 table ReshapeOptions {
735   new_shape:[int];
736 }
737
738 table SpaceToBatchNDOptions {
739 }
740
741 table BatchToSpaceNDOptions {
742 }
743
744 table SkipGramOptions {
745   ngram_size: int;
746   max_skip_size: int;
747   include_all_ngrams: bool;
748 }
749
750 table SpaceToDepthOptions {
751   block_size: int;
752 }
753
754 table DepthToSpaceOptions {
755   block_size: int;
756 }
757
758 table SubOptions {
759   fused_activation_function:ActivationFunctionType;
760   // Parameters supported by version 5
761   pot_scale_int16:bool = true;
762 }
763
764 table DivOptions {
765   fused_activation_function:ActivationFunctionType;
766 }
767
768 table TopKV2Options {
769 }
770
771 enum CombinerType : byte {
772   SUM = 0,
773   MEAN = 1,
774   SQRTN = 2,
775 }
776
777 table EmbeddingLookupSparseOptions {
778   combiner:CombinerType;
779 }
780
781 table GatherOptions {
782   axis: int;
783   // Parameters for Gather version 5 or above.
784   batch_dims: int = 0;
785 }
786
787 table TransposeOptions {
788 }
789
790 table ExpOptions {
791 }
792
793 table CosOptions {
794 }
795
796 table ReducerOptions {
797   keep_dims: bool;
798 }
799
800 table SqueezeOptions {
801   squeeze_dims:[int];
802 }
803
804 table SplitOptions {
805   num_splits: int;
806 }
807
808 table SplitVOptions {
809   num_splits: int;
810 }
811
812 table StridedSliceOptions {
813   begin_mask: int;
814   end_mask: int;
815   ellipsis_mask: int;
816   new_axis_mask: int;
817   shrink_axis_mask: int;
818 }
819
820 table LogSoftmaxOptions {
821 }
822
823 table CastOptions {
824   in_data_type: TensorType;
825   out_data_type: TensorType;
826 }
827
828 table DequantizeOptions {
829 }
830
831 table MaximumMinimumOptions {
832 }
833
834 table TileOptions {
835 }
836
837 table ArgMaxOptions {
838   output_type : TensorType;
839 }
840
841 table ArgMinOptions {
842   output_type : TensorType;
843 }
844
845 table GreaterOptions {
846 }
847
848 table GreaterEqualOptions {
849 }
850
851 table LessOptions {
852 }
853
854 table LessEqualOptions {
855 }
856
857 table NegOptions {
858 }
859
860 table SelectOptions {
861 }
862
863 table SliceOptions {
864 }
865
866 table TransposeConvOptions {
867   padding:Padding;
868   stride_w:int;
869   stride_h:int;
870 }
871
872 table ExpandDimsOptions {
873 }
874
875 table SparseToDenseOptions {
876   validate_indices:bool;
877 }
878
879 table EqualOptions {
880 }
881
882 table NotEqualOptions {
883 }
884
885 table ShapeOptions {
886   // Optional output type of the operation (int32 or int64). Defaults to int32.
887   out_type : TensorType;
888 }
889
890 table RankOptions {
891 }
892
893 table PowOptions {
894 }
895
896 table FakeQuantOptions {
897   // Parameters supported by version 1:
898   min:float;
899   max:float;
900   num_bits:int;
901
902   // Parameters supported by version 2:
903   narrow_range:bool;
904 }
905
906 table PackOptions {
907   values_count:int;
908   axis:int;
909 }
910
911 table LogicalOrOptions {
912 }
913
914 table OneHotOptions {
915   axis:int;
916 }
917
918 table AbsOptions {
919 }
920
921
922 table HardSwishOptions {
923 }
924
925 table LogicalAndOptions {
926 }
927
928 table LogicalNotOptions {
929 }
930
931 table UnpackOptions {
932   num:int;
933   axis:int;
934 }
935
936 table FloorDivOptions {
937 }
938
939 table SquareOptions {
940 }
941
942 table ZerosLikeOptions {
943 }
944
945 table FillOptions {
946 }
947
948 table FloorModOptions {
949 }
950
951 table RangeOptions {
952 }
953
954 table LeakyReluOptions {
955   alpha:float;
956 }
957
958 table SquaredDifferenceOptions {
959 }
960
961 enum MirrorPadMode : byte {
962   // Doesn't include borders.
963   REFLECT = 0,
964   // Includes borders.
965   SYMMETRIC = 1,
966 }
967
968 table MirrorPadOptions {
969   mode:MirrorPadMode;
970 }
971
972 table UniqueOptions {
973   idx_out_type:TensorType = INT32;
974 }
975
976 table ReverseV2Options {
977 }
978
979 table AddNOptions {
980 }
981
982 table GatherNdOptions {
983 }
984
985 table WhereOptions {
986 }
987
988 table ReverseSequenceOptions {
989   seq_dim:int;
990   batch_dim:int = 0;
991 }
992
993 table MatrixDiagOptions {
994 }
995
996 table QuantizeOptions {
997 }
998
999 table MatrixSetDiagOptions {
1000 }
1001
1002 table IfOptions {
1003   then_subgraph_index:int;
1004   else_subgraph_index:int;
1005 }
1006
1007 table CallOnceOptions {
1008   init_subgraph_index:int;
1009 }
1010
1011 table WhileOptions {
1012   cond_subgraph_index:int;
1013   body_subgraph_index:int;
1014 }
1015
1016 table NonMaxSuppressionV4Options {
1017 }
1018
1019 table NonMaxSuppressionV5Options {
1020 }
1021
1022 table ScatterNdOptions {
1023 }
1024
1025 table SelectV2Options {
1026 }
1027
1028 table DensifyOptions {
1029 }
1030
1031 table SegmentSumOptions {
1032 }
1033
1034 table BatchMatMulOptions {
1035   adj_x:bool;
1036   adj_y:bool;
1037   // Parameters for BatchMatMul version 4 or above.
1038   // If set to true, then weights-only op will use asymmetric quantization for
1039   // inputs.
1040   asymmetric_quantize_inputs: bool;
1041 }
1042
1043 table CumsumOptions {
1044   exclusive:bool;
1045   reverse:bool;
1046 }
1047
1048 table BroadcastToOptions {
1049 }
1050
1051 table Rfft2dOptions {
1052 }
1053
1054 table HashtableOptions {
1055   // The identity of hash tables. This identity will be used across different
1056   // subgraphs in the same interpreter instance.
1057   table_id:int;
1058   key_dtype:TensorType;
1059   value_dtype:TensorType;
1060 }
1061
1062 table HashtableFindOptions {
1063 }
1064
1065 table HashtableImportOptions {
1066 }
1067
1068 table HashtableSizeOptions {
1069 }
1070
1071 table VarHandleOptions {
1072   container:string;
1073   shared_name:string;
1074 }
1075
1076 table ReadVariableOptions {
1077 }
1078
1079 table AssignVariableOptions {
1080 }
1081
1082 // An OperatorCode can be an enum value (BuiltinOperator) if the operator is a
1083 // builtin, or a string if the operator is custom.
1084 table OperatorCode {
1085   // This field is for backward compatibility. This field will be used when
1086   // the value of the extended builtin_code field has less than
1087   // BulitinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES.
1088   deprecated_builtin_code:byte;
1089   custom_code:string;
1090
1091   // The version of the operator. The version need to be bumped whenever new
1092   // parameters are introduced into an op.
1093   version:int = 1;
1094
1095   // This field is introduced for resolving op builtin code shortage problem
1096   // (the original BuiltinOperator enum field was represented as a byte).
1097   // This field will be used when the value of the extended builtin_code field
1098   // has greater than BulitinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES.
1099   builtin_code:BuiltinOperator;
1100 }
1101
1102 enum CustomOptionsFormat : byte {
1103   FLEXBUFFERS = 0,
1104 }
1105
1106 // An operator takes tensors as inputs and outputs. The type of operation being
1107 // performed is determined by an index into the list of valid OperatorCodes,
1108 // while the specifics of each operations is configured using builtin_options
1109 // or custom_options.
1110 table Operator {
1111   // Index into the operator_codes array. Using an integer here avoids
1112   // complicate map lookups.
1113   opcode_index:uint;
1114
1115   // Optional input are indicated by -1.
1116   inputs:[int];
1117   outputs:[int];
1118
1119   builtin_options:BuiltinOptions;
1120   custom_options:[ubyte];
1121   custom_options_format:CustomOptionsFormat;
1122
1123   // A list of booleans indicating the input tensors which are being mutated by
1124   // this operator.(e.g. used by RNN and LSTM).
1125   // For example, if the "inputs" array refers to 5 tensors and the second and
1126   // fifth are mutable variables, then this list will contain
1127   // [false, true, false, false, true].
1128   //
1129   // If the list is empty, no variable is mutated in this operator.
1130   // The list either has the same length as `inputs`, or is empty.
1131   mutating_variable_inputs:[bool];
1132
1133   // A list of indices to the subgraph's "tensors" that are internal to an Op.
1134   // Internal tensors are those that do not flow in or out of the operation,
1135   // but instead are part of internal computation. As such, the operation's
1136   // implementation may manage its memory more efficiently. They are needed
1137   // however (i.e. not just an implementation detail) since they are part of the
1138   // computation, which may require relevant metadata such as quantization
1139   // parameters.
1140   intermediates:[int];
1141 }
1142
1143 // The root type, defining a subgraph, which typically represents an entire
1144 // model.
1145 table SubGraph {
1146   // A list of all tensors used in this subgraph.
1147   tensors:[Tensor];
1148
1149   // Indices of the tensors that are inputs into this subgraph. Note this is
1150   // the list of non-static tensors that feed into the subgraph for inference.
1151   inputs:[int];
1152
1153   // Indices of the tensors that are outputs out of this subgraph. Note this is
1154   // the list of output tensors that are considered the product of the
1155   // subgraph's inference.
1156   outputs:[int];
1157
1158   // All operators, in execution order.
1159   operators:[Operator];
1160
1161   // Name of this subgraph (used for debugging).
1162   name:string;
1163 }
1164
1165 // Table of raw data buffers (used for constant tensors). Referenced by tensors
1166 // by index. The generous alignment accommodates mmap-friendly data structures.
1167 table Buffer {
1168   data:[ubyte] (force_align: 16);
1169 }
1170
1171 table Metadata {
1172   // A human readable string to uniquely identify a Metadata.
1173   name:string;
1174   // An index to the buffers table.
1175   buffer:uint;
1176 }
1177
1178 // Map from an alias name of tensor to tensor index in the graph.
1179 // This is used in Signature def.
1180 table TensorMap {
1181   // Represents the alias to use for this tensor.
1182   name:string;
1183
1184   // The actual tensor index in the primary graph, that 'name' corresponds to.
1185   tensor_index:uint;
1186 }
1187
1188 // This corresponds to SignatureDef in Tensorflow SavedModel.
1189 // The SignatureDef will be part of the SavedModel provided for conversion.
1190 table SignatureDef {
1191   // Named inputs for this signature.
1192   inputs:[TensorMap];
1193
1194   // Named outputs for this signature.
1195   outputs:[TensorMap];
1196
1197   // Exported method name for this signature.
1198   method_name:string;
1199
1200   // Key value which was in the Tensorflow SavedModel SignatureDef map.
1201   key:string;
1202
1203   // Subgraph index of the exported method.
1204   subgraph_index:uint;
1205 }
1206
1207 table Model {
1208   // Version of the schema.
1209   version:uint;
1210
1211   // A list of all operator codes used in this model. This is
1212   // kept in order because operators carry an index into this
1213   // vector.
1214   operator_codes:[OperatorCode];
1215
1216   // All the subgraphs of the model. The 0th is assumed to be the main
1217   // model.
1218   subgraphs:[SubGraph];
1219
1220   // A description of the model.
1221   description:string;
1222
1223   // Buffers of the model.
1224   // Note the 0th entry of this array must be an empty buffer (sentinel).
1225   // This is a convention so that tensors without a buffer can provide 0 as
1226   // their buffer.
1227   buffers:[Buffer];
1228
1229   // Metadata about the model. Indirects into the existings buffers list.
1230   // Deprecated, prefer to use metadata field.
1231   metadata_buffer:[int];
1232
1233   // Metadata about the model.
1234   metadata:[Metadata];
1235
1236   // Optional SignatureDefs for the model.
1237   signature_defs:[SignatureDef];
1238 }
1239
1240 root_type Model;