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