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