1 // Copyright (c) 2019~2023 Samsung Electronics Co., Ltd. All Rights Reserved
2 // Copyright 2017 The TensorFlow Authors. All Rights Reserved.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 // Version Major.Minor
20 // Major version is schema version.
21 // We keep schema version if it is compatible
22 // Minor version is for human communication
23 // It will not be stored in circle model.
25 // Version 0.0: Initial version. Based on TensorFlow Lite v1.13.1 schema.
26 // Version 0.1: Based on TF v2.2-rc2 + more (from TensorFlow `56d281c`)
27 // `BATCH_MATMUL` operator, `FLOAT64` tensor type,
28 // `asymmetric_quantize_inputs` for several operator options
29 // Version 0.2: BCQ_GATHER and BCQ_FULLY_CONNECTED are added.
30 // Version 0.3: SHUFFLED16x1FLOAT32 is added.
31 // Version 0.4: Base up to TensorFlow Lite v2.7.0 schema.
32 // Version 0.5: Base up to TensorFlow Lite v2.10.1 schema.
33 // Version 0.6: Base up to TensorFlow Lite v2.13.0 schema.
37 // This corresponds to the version.
38 file_identifier "CIR0";
39 // File extension of any written files.
40 file_extension "circle";
42 // IMPORTANT: All new members of tables, enums and unions must be added at the
43 // end to ensure backwards compatibility.
45 // The type of data stored in a tensor.
46 enum TensorType : byte {
60 // Experimental: Resource and variant types are experimental, that are subject
61 // to change. Do not implement custom kernels using resource & variant types
70 // Custom quantization parameters for experimenting with new quantization
72 table CustomQuantization {
73 custom:[ubyte] (force_align: 16);
76 // Represents a specific quantization technique's parameters.
77 union QuantizationDetails {
81 // Parameters for converting a quantized tensor back to float.
82 table QuantizationParameters {
83 // These four parameters are the asymmetric linear quantization parameters.
84 // Given a quantized value q, the corresponding float value f should be:
85 // f = scale * (q - zero_point)
86 // For other quantization types, the QuantizationDetails below is used.
87 min:[float]; // For importing back into tensorflow.
88 max:[float]; // For importing back into tensorflow.
89 scale:[float]; // For dequantizing the tensor's values.
92 // If this is not none, the other quantization parameters (i.e. min, max,
93 // scale, zero_point fields above) are ignored and the value of the
94 // QuantizationDetails union should be used.
95 details:QuantizationDetails;
97 // Specifies the dimension of the Tensor's shape that the scales and
98 // zero_points correspond to. For example, a tensor t, with dims=[4, 3, 2, 1]
99 // with quantization params:
100 // scale=[1.0, 2.0, 3.0], zero_point=[1, 2, 3], quantization_dimension=1
101 // will be quantized across the second dimension of t.
102 // t[:, 0, :, :] will have scale[0]=1.0, zero_point[0]=1
103 // t[:, 1, :, :] will have scale[1]=2.0, zero_point[0]=2
104 // t[:, 2, :, :] will have scale[2]=3.0, zero_point[0]=3
105 quantized_dimension:int;
109 // We use a modification of the TACO format.
110 // Reference: http://tensor-compiler.org/kjolstad-oopsla17-tensor-compiler.pdf
112 // To encode a conceptual n-dimensional dense tensor with dims (d0, ..., dn-1),
113 // potentially with a k-dimensional block (0 <= k <= n) with dims
114 // (dn, ..., dn+k-1), the format needs to specify:
115 // 1. In what order to traverse these dimensions. For example, to store a 2-D
116 // matrix in row major order, the traversal order would be (d0, d1),
117 // whereas to store it in column major order, the traversal order would be
118 // (d1, d0). If the 2-D matrix has a 2-D inner block, the traversal order
119 // could be (d0, d1, d2, d3).
120 // 2. How each block dimension in (dn, ..., dn+k-1) maps to the original
121 // tensor dimension in (d0, ..., dn-1).
122 // 3. In the traversal order defined above, the format (dense vs. sparse) and
123 // index metadata for each dimension. For a dense dimension, this is just
124 // the size of that dimension. For a sparse dimension, it's the same as
125 // the compressed index defined in the Compressed Sparse Row (CSR) format.
126 // (http://scipy-lectures.org/advanced/scipy_sparse/csr_matrix.html)
128 // The storage type for a dimension. Currently we support:
129 // 1. DENSE: each coordinate in this dimension is stored implicitly.
130 // 2. SPARSE_CSR: only the coordinates with non-zero elements are stored. The
131 // compression technique is the same what CSR uses.
132 // More types like a sparse dimension with a different compression technique
133 // could be added to the list in the future.
134 enum DimensionType : byte {
144 values:[ushort] (force_align: 4);
148 values:[ubyte] (force_align: 4);
151 // Variable-typed buffer to store the index metadata for a sparse dimension.
152 // The widest type is Int32 instead of UInt32 because tensor's shape is a int32
153 // vector. We don't want the per-dimensional index to overflow that range.
154 union SparseIndexVector {
160 table DimensionMetadata {
161 // Whether a dimension is dense or sparse.
162 format:DimensionType;
163 // Index metadata used for a dimension.
164 // - If format is DimensionType.DENSE then we use the dense_size field to
165 // store the size of that dimension. Each index in that dimension is
166 // stored implicitly.
167 // - If format is DimensionType.SPARSE_CSR then we use array_segments and
168 // array_indices to encode that dimension. array_segments represents how
169 // to segment the indices array, each segment corresponds to one element
170 // in the previous dimension. array_indices represents the index of the
171 // non-zero elements within this dimension (as those in the CSR matrix
172 // format, where the first array is row pointers and the second array is
175 array_segments:SparseIndexVector;
176 array_indices:SparseIndexVector;
179 // Parameters to encode a sparse TfLite tensor.
180 table SparsityParameters {
181 // The traversal order of the dimensions defined in the `shape` field of the
182 // conceptual dense tensor. For a n-dimensional tensors with dims (d0, d1,
184 // - if not block sparse, the traversal_order is just a permutation of (d0,
185 // ..., dn-1). For example, a 2-D matrix stored in row-major order would
186 // have traversal_order = (d0, d1).
187 // - if block sparse with a k-dimensional block (0 <= k <= n), the
188 // traversal_order has n + k elements. The first n elements are still a
189 // permutation of (d0, ..., dn-1). The lask k elements are a permutation
190 // of (dn, ..., dn+k-1), defining how to traverse a block internally. For
191 // example, a 2-D matrix with 2-D blocks, both stored in row-major order
192 // would have traversal_order = (d0, d1, d2, d3).
193 traversal_order:[int];
194 // For an n-dimensional tensor with a k-dimensional block (0 <= k <= n),
195 // stores how a block dimension in (dn, ..., dn+k-1) maps to the original
196 // tensor dimension in (d0, ..., dn).
197 // It's stored in the order of (dn, ..., dn+k-1).
198 // If not block-sparse, this field is NULL.
200 // In the traversal order defined above, the metadata needed for
201 // each dimension to locate the non-zero values in the original dense tensor.
202 // The size of the dim_metadata array = the size of the traversal_order array
204 dim_metadata:[DimensionMetadata];
207 // The nested tensor type for VARIANT type.
208 table VariantSubType {
212 // If false, the rank or the number of tensor dimensions is unknown.
213 // If false, "shape" must be [].
214 has_rank: bool = false;
218 // The tensor shape. The meaning of each entry is operator-specific but
219 // builtin ops use: [batch size, height, width, number of channels] (That's
220 // Tensorflow's NHWC).
223 // An index that refers to the buffers table at the root of the model. Or,
224 // if there is no data buffer associated (i.e. intermediate results), then
225 // this is 0 (which refers to an always existent empty buffer).
227 // The data_buffer itself is an opaque container, with the assumption that the
228 // target device is little-endian. In addition, all builtin operators assume
229 // the memory is ordered such that if `shape` is [4, 3, 2], then index
230 // [i, j, k] maps to data_buffer[i*3*2 + j*2 + k].
232 name:string; // For debugging and importing back into tensorflow.
233 quantization:QuantizationParameters; // Optional.
235 is_variable:bool = false;
237 // Parameters to encode a sparse tensor. See the example in
238 // tensorflow/lite/testdata/sparse_tensor.json.
239 sparsity:SparsityParameters; // Optional.
241 // Encodes `shape` with unknown dimensions. Unknown dimensions are
242 // represented with -1.
243 shape_signature:[int]; // Optional.
245 // If false, the rank or the number of tensor dimensions is unknown.
246 // If false, "shape" must be [].
247 has_rank: bool = false;
249 // The nested Tensor types for VARIANT type. This is always empty for
250 // non-VARIANT types. This is optional because the nested type can be omitted.
251 // Currently only 1 subtype is supported. The field is defined as an array for
252 // flexibility of supporting multiple subtypes in the future.
253 variant_tensors:[VariantSubType];
256 // A list of builtin operators. Builtin operators are slightly faster than custom
257 // ones, but not by much. Moreover, while custom operators accept an opaque
258 // object containing configuration parameters, builtins have a predetermined
259 // set of acceptable options.
261 enum BuiltinOperator : int32 {
263 BCQ_FULLY_CONNECTED = -3,
269 DEPTHWISE_CONV_2D = 4,
272 EMBEDDING_LOOKUP = 7,
275 HASHTABLE_LOOKUP = 10,
276 L2_NORMALIZATION = 11,
278 LOCAL_RESPONSE_NORMALIZATION = 13,
285 // NOTE(aselle): RELU_N1_TO_1 used to be called RELU1, but it was renamed
286 // since different model developers use RELU1 in different ways. Never
287 // create another op called RELU1.
291 RESIZE_BILINEAR = 23,
297 CONCAT_EMBEDDINGS = 29,
301 EMBEDDING_LOOKUP_SPARSE = 33,
303 UNIDIRECTIONAL_SEQUENCE_RNN = 35,
305 BATCH_TO_SPACE_ND = 37,
306 SPACE_TO_BATCH_ND = 38,
312 UNIDIRECTIONAL_SEQUENCE_LSTM = 44,
314 BIDIRECTIONAL_SEQUENCE_RNN = 46,
319 // DELEGATE is a special op type for the operations which are delegated to
321 // WARNING: Experimental interface, subject to change
323 BIDIRECTIONAL_SEQUENCE_LSTM = 52,
339 SPARSE_TO_DENSE = 68,
368 RESIZE_NEAREST_NEIGHBOR = 97,
370 SQUARED_DIFFERENCE = 99,
383 REVERSE_SEQUENCE = 112,
386 MATRIX_SET_DIAG = 115,
391 NON_MAX_SUPPRESSION_V4 = 120,
392 NON_MAX_SUPPRESSION_V5 = 121,
398 PLACEHOLDER_FOR_GREATER_OP_CODES = 127,
408 HASHTABLE_FIND = 137,
409 HASHTABLE_IMPORT = 138,
410 HASHTABLE_SIZE = 139,
412 CONV_3D_TRANSPOSE = 141,
415 ASSIGN_VARIABLE = 144,
416 BROADCAST_ARGS = 145,
417 RANDOM_STANDARD_NORMAL = 146,
419 RANDOM_UNIFORM = 148,
422 DYNAMIC_UPDATE_SLICE = 151,
424 UNSORTED_SEGMENT_PROD = 153,
425 UNSORTED_SEGMENT_MAX = 154,
426 UNSORTED_SEGMENT_SUM = 155,
428 UNSORTED_SEGMENT_MIN = 157,
434 // LINT.ThenChange(nnapi_linter/linter.proto)
436 // Options for the builtin operators.
437 union BuiltinOptions {
439 DepthwiseConv2DOptions,
440 ConcatEmbeddingsOptions,
441 LSHProjectionOptions,
445 FullyConnectedOptions,
447 ConcatenationOptions,
450 LocalResponseNormalizationOptions,
452 ResizeBilinearOptions,
457 EmbeddingLookupSparseOptions,
461 BatchToSpaceNDOptions,
462 SpaceToBatchNDOptions,
476 MaximumMinimumOptions,
486 TransposeConvOptions,
487 SparseToDenseOptions,
506 BidirectionalSequenceLSTMOptions,
507 BidirectionalSequenceRNNOptions,
508 UnidirectionalSequenceLSTMOptions,
511 ResizeNearestNeighborOptions,
513 SquaredDifferenceOptions,
524 ReverseSequenceOptions,
527 MatrixSetDiagOptions,
532 NonMaxSuppressionV4Options,
533 NonMaxSuppressionV5Options,
545 HashtableFindOptions,
546 HashtableImportOptions,
547 HashtableSizeOptions,
550 AssignVariableOptions,
554 DynamicUpdateSliceOptions,
555 UnsortedSegmentProdOptions,
556 UnsortedSegmentMaxOptions,
557 UnsortedSegmentMinOptions,
558 UnsortedSegmentSumOptions,
564 BCQGatherOptions = 252,
565 BCQFullyConnectedOptions = 253,
566 InstanceNormOptions = 254,
569 enum Padding : byte { SAME, VALID }
571 enum ActivationFunctionType : byte {
580 table Conv2DOptions {
584 fused_activation_function:ActivationFunctionType;
585 dilation_w_factor:int = 1;
586 dilation_h_factor:int = 1;
589 // Options for both Conv3D and Conv3DTranspose.
590 table Conv3DOptions {
595 fused_activation_function:ActivationFunctionType;
596 dilation_d_factor:int = 1;
597 dilation_w_factor:int = 1;
598 dilation_h_factor:int = 1;
601 table Pool2DOptions {
607 fused_activation_function:ActivationFunctionType;
610 table DepthwiseConv2DOptions {
611 // Parameters for DepthwiseConv version 1 or above.
615 // `depth_multiplier` is redundant. It's used by CPU kernels in
616 // TensorFlow 2.0 or below, but ignored in versions above.
617 // See comments in lite/c/builtin_op_data.h for more details.
618 depth_multiplier:int;
619 fused_activation_function:ActivationFunctionType;
620 // Parameters for DepthwiseConv version 2 or above.
621 dilation_w_factor:int = 1;
622 dilation_h_factor:int = 1;
625 table ConcatEmbeddingsOptions {
627 num_columns_per_channel:[int];
628 embedding_dim_per_channel:[int]; // This could be inferred from parameters.
631 enum LSHProjectionType: byte {
637 table LSHProjectionOptions {
638 type: LSHProjectionType;
643 fused_activation_function:ActivationFunctionType;
644 // For weights-only quantization, use asymmetric quantization for non
645 // constant inputs at evaluation time.
646 asymmetric_quantize_inputs:bool;
649 // An implementation of TensorFlow RNNCell.
651 fused_activation_function:ActivationFunctionType;
652 asymmetric_quantize_inputs:bool;
655 // An implementation of TensorFlow dynamic_rnn with RNNCell.
656 table SequenceRNNOptions {
658 fused_activation_function:ActivationFunctionType;
659 asymmetric_quantize_inputs:bool;
662 // An implementation of TensorFlow bidrectional_dynamic_rnn with RNNCell.
663 table BidirectionalSequenceRNNOptions {
665 fused_activation_function:ActivationFunctionType;
667 asymmetric_quantize_inputs:bool;
670 enum FullyConnectedOptionsWeightsFormat: byte {
672 SHUFFLED4x16INT8 = 1,
673 SHUFFLED16x1FLOAT32 = 127
676 // An implementation of TensorFlow fully_connected (a.k.a Dense) layer.
677 table FullyConnectedOptions {
678 // Parameters for FullyConnected version 1 or above.
679 fused_activation_function:ActivationFunctionType;
681 // Parameters for FullyConnected version 2 or above.
682 weights_format:FullyConnectedOptionsWeightsFormat = DEFAULT;
684 // Parameters for FullyConnected version 5 or above.
685 // If set to true, then the number of dimension is preserved. Furthermore,
686 // all but the last dimension of the input and output shapes will be equal.
689 // Parameters for FullyConnected version 7 or above.
690 // If set to true, then weights-only op will use asymmetric quantization for
692 asymmetric_quantize_inputs: bool;
695 table SoftmaxOptions {
699 // An implementation of TensorFlow concat.
700 table ConcatenationOptions {
702 fused_activation_function:ActivationFunctionType;
706 fused_activation_function:ActivationFunctionType;
707 // Parameters supported by version 3.
708 pot_scale_int16:bool = true;
712 fused_activation_function:ActivationFunctionType;
715 table L2NormOptions {
716 // This field is currently ignored in the L2 Norm Op.
717 fused_activation_function:ActivationFunctionType;
720 table LocalResponseNormalizationOptions {
727 enum LSTMKernelType : byte {
728 // Full LSTM kernel which supports peephole and projection.
730 // Basic LSTM kernels. Equivalent to TensorFlow BasicLSTMCell.
734 // An implementation of TensorFlow LSTMCell and CoupledInputForgetGateLSTMCell
736 // Parameters for LSTM version 1 or above.
737 fused_activation_function:ActivationFunctionType;
738 cell_clip: float; // Optional, 0.0 means no clipping
739 proj_clip: float; // Optional, 0.0 means no clipping
741 // Parameters for LSTM version 2 or above.
742 // Basic kernel is only supported in version 2 or above.
743 kernel_type: LSTMKernelType = FULL;
745 // Parameters for LSTM version 4 or above.
746 asymmetric_quantize_inputs: bool;
749 // An implementation of TensorFlow dynamic_rnn with LSTMCell.
750 table UnidirectionalSequenceLSTMOptions {
751 fused_activation_function:ActivationFunctionType;
752 cell_clip: float; // Optional, 0.0 means no clipping
753 proj_clip: float; // Optional, 0.0 means no clipping
755 // If true then first dimension is sequence, otherwise batch.
758 // Parameter for Unidirectional Sequence LSTM version 3.
759 asymmetric_quantize_inputs:bool;
761 // Parameter for unidirectional sequence RNN version 4.
762 diagonal_recurrent_tensors:bool;
765 table BidirectionalSequenceLSTMOptions {
766 // Parameters supported by version 1:
767 fused_activation_function:ActivationFunctionType;
768 cell_clip: float; // Optional, 0.0 means no clipping
769 proj_clip: float; // Optional, 0.0 means no clipping
771 // If true, store the outputs of both directions into the first output.
774 // Parameters supported by version 2:
775 // If true then first dimension is sequence, otherwise batch.
776 // Version 1 implementations assumed time_major to be true, so this default
777 // value should never change.
778 time_major: bool = true;
780 // Parameters for version 3 or above.
781 asymmetric_quantize_inputs:bool;
784 table ResizeBilinearOptions {
785 new_height: int (deprecated);
786 new_width: int (deprecated);
788 half_pixel_centers: bool;
791 table ResizeNearestNeighborOptions {
793 half_pixel_centers: bool;
796 // A call operation options
798 // The subgraph index that needs to be called.
808 table ReshapeOptions {
812 table SpaceToBatchNDOptions {
815 table BatchToSpaceNDOptions {
818 table SkipGramOptions {
821 include_all_ngrams: bool;
824 table SpaceToDepthOptions {
828 table DepthToSpaceOptions {
833 fused_activation_function:ActivationFunctionType;
834 // Parameters supported by version 5
835 pot_scale_int16:bool = true;
839 fused_activation_function:ActivationFunctionType;
842 table TopKV2Options {
845 enum CombinerType : byte {
851 table EmbeddingLookupSparseOptions {
852 combiner:CombinerType;
855 table GatherOptions {
857 // Parameters for Gather version 5 or above.
861 table TransposeOptions {
870 table ReducerOptions {
874 table SqueezeOptions {
882 table SplitVOptions {
886 table StridedSliceOptions {
891 shrink_axis_mask: int;
894 table LogSoftmaxOptions {
898 in_data_type: TensorType;
899 out_data_type: TensorType;
902 table DequantizeOptions {
905 table MaximumMinimumOptions {
911 table ArgMaxOptions {
912 output_type : TensorType;
915 table ArgMinOptions {
916 output_type : TensorType;
919 table GreaterOptions {
922 table GreaterEqualOptions {
928 table LessEqualOptions {
934 table SelectOptions {
940 table TransposeConvOptions {
941 // Parameters supported by version 1, 2, 3:
946 // Parameters supported by version 4:
947 fused_activation_function:ActivationFunctionType = NONE;
950 table ExpandDimsOptions {
953 table SparseToDenseOptions {
954 validate_indices:bool;
960 table NotEqualOptions {
964 // Optional output type of the operation (int32 or int64). Defaults to int32.
965 out_type : TensorType;
974 table FakeQuantOptions {
975 // Parameters supported by version 1:
980 // Parameters supported by version 2:
989 table LogicalOrOptions {
992 table OneHotOptions {
1000 table HardSwishOptions {
1003 table LogicalAndOptions {
1006 table LogicalNotOptions {
1009 table UnpackOptions {
1014 table FloorDivOptions {
1017 table SquareOptions {
1020 table ZerosLikeOptions {
1026 table FloorModOptions {
1029 table RangeOptions {
1032 table LeakyReluOptions {
1036 table SquaredDifferenceOptions {
1039 enum MirrorPadMode : byte {
1040 // Doesn't include borders.
1042 // Includes borders.
1046 table MirrorPadOptions {
1050 table UniqueOptions {
1051 idx_out_type:TensorType = INT32;
1054 table ReverseV2Options {
1060 table GatherNdOptions {
1063 table WhereOptions {
1066 table ReverseSequenceOptions {
1071 table MatrixDiagOptions {
1074 table QuantizeOptions {
1077 table MatrixSetDiagOptions {
1081 then_subgraph_index:int;
1082 else_subgraph_index:int;
1085 table CallOnceOptions {
1086 init_subgraph_index:int;
1089 table WhileOptions {
1090 cond_subgraph_index:int;
1091 body_subgraph_index:int;
1094 table NonMaxSuppressionV4Options {
1097 table NonMaxSuppressionV5Options {
1100 table ScatterNdOptions {
1103 table SelectV2Options {
1106 table DensifyOptions {
1109 table SegmentSumOptions {
1112 table BatchMatMulOptions {
1115 // Parameters for BatchMatMul version 4 or above.
1116 // If set to true, then weights-only op will use asymmetric quantization for
1118 asymmetric_quantize_inputs: bool;
1121 table CumsumOptions {
1126 table BroadcastToOptions {
1129 table Rfft2dOptions {
1132 table HashtableOptions {
1133 // The identity of hash tables. This identity will be used across different
1134 // subgraphs in the same interpreter instance.
1136 key_dtype:TensorType;
1137 value_dtype:TensorType;
1140 table HashtableFindOptions {
1143 table HashtableImportOptions {
1146 table HashtableSizeOptions {
1149 table VarHandleOptions {
1154 table ReadVariableOptions {
1157 table AssignVariableOptions {
1160 table RandomOptions {
1165 table BucketizeOptions {
1166 boundaries: [float]; // The bucket boundaries.
1173 table DynamicUpdateSliceOptions {
1176 table UnsortedSegmentProdOptions {
1179 table UnsortedSegmentMaxOptions {
1182 table UnsortedSegmentSumOptions {
1185 table ATan2Options {
1188 table UnsortedSegmentMinOptions{
1194 table BitcastOptions {
1197 table BitwiseXorOptions {
1200 table RightShiftOptions {
1203 table BCQGatherOptions {
1204 input_hidden_size: int;
1208 table BCQFullyConnectedOptions {
1209 weights_hidden_size: int;
1210 fused_activation_function:ActivationFunctionType;
1213 table InstanceNormOptions {
1215 fused_activation_function:ActivationFunctionType;
1218 // An OperatorCode can be an enum value (BuiltinOperator) if the operator is a
1219 // builtin, or a string if the operator is custom.
1220 table OperatorCode {
1221 // This field is for backward compatibility. This field will be used when
1222 // the value of the extended builtin_code field has less than
1223 // BulitinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES.
1224 deprecated_builtin_code:byte;
1227 // The version of the operator. The version need to be bumped whenever new
1228 // parameters are introduced into an op.
1231 // This field is introduced for resolving op builtin code shortage problem
1232 // (the original BuiltinOperator enum field was represented as a byte).
1233 // This field will be used when the value of the extended builtin_code field
1234 // has greater than BulitinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES.
1235 builtin_code:BuiltinOperator;
1238 enum CustomOptionsFormat : byte {
1242 enum DataFormat : byte {
1243 // For 2D data, NHWC(batch, height, width, channels)
1244 // For 3D data, NDHWC(batch, depth, height, width, channels)
1246 // For 2D data, NCHW(batch, channels, height, width)
1247 // For 3D data, NCDHW(batch, channels, depth, height, width)
1251 // An operator takes tensors as inputs and outputs. The type of operation being
1252 // performed is determined by an index into the list of valid OperatorCodes,
1253 // while the specifics of each operations is configured using builtin_options
1254 // or custom_options.
1256 // Index into the operator_codes array. Using an integer here avoids
1257 // complicate map lookups.
1260 // Optional input are indicated by -1.
1264 builtin_options:BuiltinOptions;
1265 custom_options:[ubyte];
1266 custom_options_format:CustomOptionsFormat;
1268 // A list of booleans indicating the input tensors which are being mutated by
1269 // this operator.(e.g. used by RNN and LSTM).
1270 // For example, if the "inputs" array refers to 5 tensors and the second and
1271 // fifth are mutable variables, then this list will contain
1272 // [false, true, false, false, true].
1274 // If the list is empty, no variable is mutated in this operator.
1275 // The list either has the same length as `inputs`, or is empty.
1276 mutating_variable_inputs:[bool];
1278 // A list of indices to the subgraph's "tensors" that are internal to an Op.
1279 // Internal tensors are those that do not flow in or out of the operation,
1280 // but instead are part of internal computation. As such, the operation's
1281 // implementation may manage its memory more efficiently. They are needed
1282 // however (i.e. not just an implementation detail) since they are part of the
1283 // computation, which may require relevant metadata such as quantization
1285 intermediates:[int];
1288 // The root type, defining a subgraph, which typically represents an entire
1291 // A list of all tensors used in this subgraph.
1294 // Indices of the tensors that are inputs into this subgraph. Note this is
1295 // the list of non-static tensors that feed into the subgraph for inference.
1298 // Indices of the tensors that are outputs out of this subgraph. Note this is
1299 // the list of output tensors that are considered the product of the
1300 // subgraph's inference.
1303 // All operators, in execution order.
1304 operators:[Operator];
1306 // Name of this subgraph (used for debugging).
1309 // Data format for input/output of SubGraph
1310 data_format: DataFormat;
1313 // Table of raw data buffers (used for constant tensors). Referenced by tensors
1314 // by index. The generous alignment accommodates mmap-friendly data structures.
1316 data:[ubyte] (force_align: 16);
1320 // A human readable string to uniquely identify a Metadata.
1322 // An index to the buffers table.
1326 // Map from an alias name of tensor to tensor index in the graph.
1327 // This is used in Signature def.
1329 // Represents the alias to use for this tensor.
1332 // The actual tensor index in the primary graph, that 'name' corresponds to.
1336 // This corresponds to SignatureDef in Tensorflow SavedModel.
1337 // The SignatureDef will be part of the SavedModel provided for conversion.
1338 table SignatureDef {
1339 // Named inputs for this signature.
1342 // Named outputs for this signature.
1343 outputs:[TensorMap];
1345 // Key value which was in the Tensorflow SavedModel SignatureDef map.
1346 signature_key:string;
1348 // Model tag, deprecated.
1349 deprecated_tag:string (deprecated);
1351 // Index of subgraphs that corresponds to the exported method.
1352 subgraph_index:uint;
1356 // Version of the schema.
1359 // A list of all operator codes used in this model. This is
1360 // kept in order because operators carry an index into this
1362 operator_codes:[OperatorCode];
1364 // All the subgraphs of the model. The 0th is assumed to be the main
1366 subgraphs:[SubGraph];
1368 // A description of the model.
1371 // Buffers of the model.
1372 // Note the 0th entry of this array must be an empty buffer (sentinel).
1373 // This is a convention so that tensors without a buffer can provide 0 as
1377 // Metadata about the model. Indirects into the existings buffers list.
1378 // Deprecated, prefer to use metadata field.
1379 metadata_buffer:[int];
1381 // Metadata about the model.
1382 metadata:[Metadata];
1384 // Optional SignatureDefs for the model.
1385 signature_defs:[SignatureDef];