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