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