| 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 |
/// WARNING: Users of TensorFlow Lite should not include this file directly, |
| 16 |
/// but should instead include |
| 17 |
/// "third_party/tensorflow/lite/c/builtin_op_data.h". |
| 18 |
/// Only the TensorFlow Lite implementation itself should include this |
| 19 |
/// file directly. |
| 20 |
#ifndef TENSORFLOW_LITE_CORE_C_BUILTIN_OP_DATA_H_ |
| 21 |
#define TENSORFLOW_LITE_CORE_C_BUILTIN_OP_DATA_H_ |
| 22 |
|
| 23 |
#include <stdint.h> |
| 24 |
|
| 25 |
#include "tensorflow/lite/core/c/common.h" |
| 26 |
|
| 27 |
#ifdef __cplusplus |
| 28 |
extern "C" { |
| 29 |
#endif // __cplusplus |
| 30 |
|
| 31 |
// TfLiteReshapeParams can't have dynamic data so we fix the maximum possible |
| 32 |
// number of dimensions. |
| 33 |
#define TFLITE_RESHAPE_PARAMS_MAX_DIMENSION_COUNT 8 |
| 34 |
|
| 35 |
// TODO(aselle): Consider using "if this then that" for testing. |
| 36 |
|
| 37 |
// Useful placeholder to put in otherwise empty structs to avoid size warnings. |
| 38 |
typedef struct { |
| 39 |
char dummy; |
| 40 |
} EmptyStructPlaceholder; |
| 41 |
|
| 42 |
// IMPORTANT: All new members of structs must be added at the end to ensure |
| 43 |
// backwards compatibility. |
| 44 |
|
| 45 |
// Possible padding types (for convolutions) |
| 46 |
typedef enum { |
| 47 |
kTfLitePaddingUnknown = 0, |
| 48 |
kTfLitePaddingSame, |
| 49 |
kTfLitePaddingValid, |
| 50 |
} TfLitePadding; |
| 51 |
|
| 52 |
typedef enum { |
| 53 |
kTfLiteMirrorPaddingUnknown = 0, |
| 54 |
kTfLiteMirrorPaddingReflect, |
| 55 |
kTfLiteMirrorPaddingSymmetric, |
| 56 |
} TfLiteMirrorPaddingMode; |
| 57 |
|
| 58 |
// TODO(b/130259536): We should move this out of builtin_op_data. |
| 59 |
typedef struct { |
| 60 |
int width; |
| 61 |
int height; |
| 62 |
int width_offset; |
| 63 |
int height_offset; |
| 64 |
} TfLitePaddingValues; |
| 65 |
|
| 66 |
typedef struct { |
| 67 |
TfLiteMirrorPaddingMode mode; |
| 68 |
} TfLiteMirrorPaddingParams; |
| 69 |
|
| 70 |
// Possible fused activation functions. |
| 71 |
typedef enum { |
| 72 |
kTfLiteActNone = 0, |
| 73 |
kTfLiteActRelu, |
| 74 |
kTfLiteActReluN1To1, // min(max(-1, x), 1) |
| 75 |
kTfLiteActRelu6, // min(max(0, x), 6) |
| 76 |
kTfLiteActTanh, |
| 77 |
kTfLiteActSignBit, |
| 78 |
kTfLiteActSigmoid, |
| 79 |
} TfLiteFusedActivation; |
| 80 |
|
| 81 |
typedef struct { |
| 82 |
// Parameters for CONV_2D version 1. |
| 83 |
TfLitePadding padding; |
| 84 |
int stride_width; |
| 85 |
int stride_height; |
| 86 |
TfLiteFusedActivation activation; |
| 87 |
|
| 88 |
// Parameters for CONV_2D version 2. |
| 89 |
// Note: Version 2 supports dilation values not equal to 1. |
| 90 |
int dilation_width_factor; |
| 91 |
int dilation_height_factor; |
| 92 |
} TfLiteConvParams; |
| 93 |
|
| 94 |
typedef struct { |
| 95 |
TfLitePadding padding; |
| 96 |
int stride_width; |
| 97 |
int stride_height; |
| 98 |
int stride_depth; |
| 99 |
int dilation_width_factor; |
| 100 |
int dilation_height_factor; |
| 101 |
int dilation_depth_factor; |
| 102 |
TfLiteFusedActivation activation; |
| 103 |
} TfLiteConv3DParams; |
| 104 |
|
| 105 |
typedef TfLiteConv3DParams TfLiteConv3DTransposeParams; |
| 106 |
|
| 107 |
typedef struct { |
| 108 |
TfLitePadding padding; |
| 109 |
int stride_width; |
| 110 |
int stride_height; |
| 111 |
int filter_width; |
| 112 |
int filter_height; |
| 113 |
TfLiteFusedActivation activation; |
| 114 |
struct { |
| 115 |
TfLitePaddingValues padding; |
| 116 |
} computed; |
| 117 |
} TfLitePoolParams; |
| 118 |
|
| 119 |
typedef struct { |
| 120 |
// Parameters for DepthwiseConv version 1 or above. |
| 121 |
TfLitePadding padding; |
| 122 |
int stride_width; |
| 123 |
int stride_height; |
| 124 |
// `depth_multiplier` is redundant. It's used by CPU kernels in |
| 125 |
// TensorFlow 2.0 or below, but ignored in versions above. |
| 126 |
// |
| 127 |
// The information can be deduced from the shape of input and the shape of |
| 128 |
// weights. Since the TFLiteConverter toolchain doesn't support partially |
| 129 |
// specified shapes, relying on `depth_multiplier` stops us from supporting |
| 130 |
// graphs with dynamic shape tensors. |
| 131 |
// |
| 132 |
// Note: Some of the delegates (e.g. NNAPI, GPU) are still relying on this |
| 133 |
// field. |
| 134 |
int depth_multiplier; |
| 135 |
TfLiteFusedActivation activation; |
| 136 |
// Parameters for DepthwiseConv version 2 or above. |
| 137 |
int dilation_width_factor; |
| 138 |
int dilation_height_factor; |
| 139 |
} TfLiteDepthwiseConvParams; |
| 140 |
|
| 141 |
typedef struct { |
| 142 |
int rank; |
| 143 |
TfLiteFusedActivation activation; |
| 144 |
|
| 145 |
// Parameter for SVDF version 4. |
| 146 |
bool asymmetric_quantize_inputs; |
| 147 |
} TfLiteSVDFParams; |
| 148 |
|
| 149 |
typedef struct { |
| 150 |
TfLiteFusedActivation activation; |
| 151 |
|
| 152 |
// Parameter for RNN version 3. |
| 153 |
bool asymmetric_quantize_inputs; |
| 154 |
} TfLiteRNNParams; |
| 155 |
|
| 156 |
typedef struct { |
| 157 |
bool time_major; |
| 158 |
TfLiteFusedActivation activation; |
| 159 |
|
| 160 |
// Parameter for Sequence RNN version 3. |
| 161 |
bool asymmetric_quantize_inputs; |
| 162 |
} TfLiteSequenceRNNParams; |
| 163 |
|
| 164 |
typedef struct { |
| 165 |
bool time_major; |
| 166 |
TfLiteFusedActivation activation; |
| 167 |
bool merge_outputs; |
| 168 |
|
| 169 |
// Parameter for Bidirectional RNN verison 3. |
| 170 |
bool asymmetric_quantize_inputs; |
| 171 |
} TfLiteBidirectionalSequenceRNNParams; |
| 172 |
|
| 173 |
typedef enum { |
| 174 |
kTfLiteFullyConnectedWeightsFormatDefault = 0, |
| 175 |
kTfLiteFullyConnectedWeightsFormatShuffled4x16Int8 = 1, |
| 176 |
} TfLiteFullyConnectedWeightsFormat; |
| 177 |
|
| 178 |
typedef struct { |
| 179 |
// Parameters for FullyConnected version 1 or above. |
| 180 |
TfLiteFusedActivation activation; |
| 181 |
|
| 182 |
// Parameters for FullyConnected version 2 or above. |
| 183 |
TfLiteFullyConnectedWeightsFormat weights_format; |
| 184 |
|
| 185 |
// Parameters for FullyConnected version 5 or above. |
| 186 |
// If set to true, then the number of dimensions in the input and the output |
| 187 |
// tensors are the same. Furthermore, all but the last dimension of the input |
| 188 |
// and output shapes will be equal. |
| 189 |
bool keep_num_dims; |
| 190 |
|
| 191 |
// Parameters for FullyConnected version 7 or above. |
| 192 |
// If set to true and the weights are quantized, then non constant inputs |
| 193 |
// are quantized at evaluation time with asymmetric quantization. |
| 194 |
bool asymmetric_quantize_inputs; |
| 195 |
} TfLiteFullyConnectedParams; |
| 196 |
|
| 197 |
typedef enum { |
| 198 |
kTfLiteLshProjectionUnknown = 0, |
| 199 |
kTfLiteLshProjectionSparse = 1, |
| 200 |
kTfLiteLshProjectionDense = 2, |
| 201 |
} TfLiteLSHProjectionType; |
| 202 |
|
| 203 |
typedef struct { |
| 204 |
TfLiteLSHProjectionType type; |
| 205 |
} TfLiteLSHProjectionParams; |
| 206 |
|
| 207 |
typedef struct { |
| 208 |
float beta; |
| 209 |
} TfLiteSoftmaxParams; |
| 210 |
|
| 211 |
typedef struct { |
| 212 |
int axis; |
| 213 |
TfLiteFusedActivation activation; |
| 214 |
} TfLiteConcatenationParams; |
| 215 |
|
| 216 |
typedef struct { |
| 217 |
TfLiteFusedActivation activation; |
| 218 |
// Parameter added for the version 4. |
| 219 |
bool pot_scale_int16; |
| 220 |
} TfLiteAddParams; |
| 221 |
|
| 222 |
typedef struct { |
| 223 |
EmptyStructPlaceholder placeholder; |
| 224 |
} TfLiteSpaceToBatchNDParams; |
| 225 |
|
| 226 |
typedef struct { |
| 227 |
EmptyStructPlaceholder placeholder; |
| 228 |
} TfLiteBatchToSpaceNDParams; |
| 229 |
|
| 230 |
typedef struct { |
| 231 |
bool adj_x; |
| 232 |
bool adj_y; |
| 233 |
// Parameters for BatchMatMul version 4 or above. |
| 234 |
// If set to true and the weights are quantized, then non constant inputs |
| 235 |
// are quantized at evaluation time with asymmetric quantization. |
| 236 |
bool asymmetric_quantize_inputs; |
| 237 |
} TfLiteBatchMatMulParams; |
| 238 |
|
| 239 |
typedef struct { |
| 240 |
TfLiteFusedActivation activation; |
| 241 |
} TfLiteMulParams; |
| 242 |
|
| 243 |
typedef struct { |
| 244 |
TfLiteFusedActivation activation; |
| 245 |
// Parameter added for the version 5. |
| 246 |
bool pot_scale_int16; |
| 247 |
} TfLiteSubParams; |
| 248 |
|
| 249 |
typedef struct { |
| 250 |
TfLiteFusedActivation activation; |
| 251 |
} TfLiteDivParams; |
| 252 |
|
| 253 |
typedef struct { |
| 254 |
TfLiteFusedActivation activation; |
| 255 |
} TfLiteL2NormParams; |
| 256 |
|
| 257 |
typedef struct { |
| 258 |
int radius; |
| 259 |
float bias; |
| 260 |
float alpha; |
| 261 |
float beta; |
| 262 |
} TfLiteLocalResponseNormParams; |
| 263 |
|
| 264 |
typedef enum { |
| 265 |
kTfLiteLSTMFullKernel = 0, |
| 266 |
kTfLiteLSTMBasicKernel |
| 267 |
} TfLiteLSTMKernelType; |
| 268 |
|
| 269 |
typedef struct { |
| 270 |
// Parameters for LSTM version 1. |
| 271 |
TfLiteFusedActivation activation; |
| 272 |
float cell_clip; |
| 273 |
float proj_clip; |
| 274 |
|
| 275 |
// Parameters for LSTM version 2. |
| 276 |
// kTfLiteLSTMBasicKernel is only supported in version 2 or above. |
| 277 |
TfLiteLSTMKernelType kernel_type; |
| 278 |
|
| 279 |
// Parameters for LSTM version 4. |
| 280 |
bool asymmetric_quantize_inputs; |
| 281 |
} TfLiteLSTMParams; |
| 282 |
|
| 283 |
typedef struct { |
| 284 |
// Parameters needed for the underlying LSTM. |
| 285 |
TfLiteFusedActivation activation; |
| 286 |
float cell_clip; |
| 287 |
float proj_clip; |
| 288 |
|
| 289 |
// If set to true then the first dimension is time, otherwise batch. |
| 290 |
bool time_major; |
| 291 |
|
| 292 |
// Parameter for unidirectional sequence RNN version 3. |
| 293 |
bool asymmetric_quantize_inputs; |
| 294 |
|
| 295 |
// Parameter for unidirectional sequence RNN version 4. |
| 296 |
bool diagonal_recurrent_tensors; |
| 297 |
} TfLiteUnidirectionalSequenceLSTMParams; |
| 298 |
|
| 299 |
typedef struct { |
| 300 |
// Parameters supported by version 1: |
| 301 |
// Parameters inherited for the LSTM kernel. |
| 302 |
TfLiteFusedActivation activation; |
| 303 |
float cell_clip; |
| 304 |
float proj_clip; |
| 305 |
|
| 306 |
// If true, store the outputs of both directions in the first output. |
| 307 |
bool merge_outputs; |
| 308 |
|
| 309 |
// Parameters supported by version 2: |
| 310 |
// If set to true then the first dimension is time, otherwise batch. |
| 311 |
bool time_major; |
| 312 |
|
| 313 |
// Parameters supported by version 3: |
| 314 |
// If set to true, then hybrid ops use asymmetric quantization for inputs. |
| 315 |
bool asymmetric_quantize_inputs; |
| 316 |
} TfLiteBidirectionalSequenceLSTMParams; |
| 317 |
|
| 318 |
typedef struct { |
| 319 |
bool align_corners; |
| 320 |
// half_pixel_centers assumes pixels are of half the actual dimensions, and |
| 321 |
// yields more accurate resizes. Corresponds to the same argument for the |
| 322 |
// original TensorFlow op in TF2.0. |
| 323 |
bool half_pixel_centers; |
| 324 |
} TfLiteResizeBilinearParams; |
| 325 |
|
| 326 |
typedef struct { |
| 327 |
bool align_corners; |
| 328 |
bool half_pixel_centers; |
| 329 |
} TfLiteResizeNearestNeighborParams; |
| 330 |
|
| 331 |
typedef struct { |
| 332 |
EmptyStructPlaceholder placeholder; |
| 333 |
} TfLitePadParams; |
| 334 |
|
| 335 |
typedef struct { |
| 336 |
EmptyStructPlaceholder placeholder; |
| 337 |
} TfLitePadV2Params; |
| 338 |
|
| 339 |
typedef struct { |
| 340 |
// These fields are only used in old models for backward compatibility. |
| 341 |
// In the current implementation, we use the 2nd input of the op as the shape, |
| 342 |
// and these fields are unused. |
| 343 |
int shape[TFLITE_RESHAPE_PARAMS_MAX_DIMENSION_COUNT]; |
| 344 |
int num_dimensions; |
| 345 |
} TfLiteReshapeParams; |
| 346 |
|
| 347 |
typedef struct { |
| 348 |
int ngram_size; |
| 349 |
int max_skip_size; |
| 350 |
bool include_all_ngrams; |
| 351 |
} TfLiteSkipGramParams; |
| 352 |
|
| 353 |
typedef struct { |
| 354 |
int block_size; |
| 355 |
} TfLiteSpaceToDepthParams; |
| 356 |
|
| 357 |
typedef struct { |
| 358 |
int block_size; |
| 359 |
} TfLiteDepthToSpaceParams; |
| 360 |
|
| 361 |
typedef struct { |
| 362 |
TfLiteType in_data_type; |
| 363 |
TfLiteType out_data_type; |
| 364 |
} TfLiteCastParams; |
| 365 |
|
| 366 |
typedef enum { |
| 367 |
kTfLiteCombinerTypeSum = 0, |
| 368 |
kTfLiteCombinerTypeMean = 1, |
| 369 |
kTfLiteCombinerTypeSqrtn = 2, |
| 370 |
} TfLiteCombinerType; |
| 371 |
|
| 372 |
typedef struct { |
| 373 |
TfLiteCombinerType combiner; |
| 374 |
} TfLiteEmbeddingLookupSparseParams; |
| 375 |
|
| 376 |
typedef struct { |
| 377 |
int axis; |
| 378 |
int batch_dims; |
| 379 |
} TfLiteGatherParams; |
| 380 |
|
| 381 |
typedef struct { |
| 382 |
EmptyStructPlaceholder placeholder; |
| 383 |
} TfLiteTransposeParams; |
| 384 |
|
| 385 |
typedef struct { |
| 386 |
bool keep_dims; |
| 387 |
} TfLiteReducerParams; |
| 388 |
|
| 389 |
typedef struct { |
| 390 |
int num_splits; |
| 391 |
} TfLiteSplitParams; |
| 392 |
|
| 393 |
typedef struct { |
| 394 |
int num_splits; |
| 395 |
} TfLiteSplitVParams; |
| 396 |
|
| 397 |
typedef struct { |
| 398 |
// TODO(ahentz): We can't have dynamic data in this struct, at least not yet. |
| 399 |
// For now we will fix the maximum possible number of dimensions. |
| 400 |
int squeeze_dims[8]; |
| 401 |
int num_squeeze_dims; |
| 402 |
} TfLiteSqueezeParams; |
| 403 |
|
| 404 |
typedef struct { |
| 405 |
int begin_mask; |
| 406 |
int end_mask; |
| 407 |
int ellipsis_mask; |
| 408 |
int new_axis_mask; |
| 409 |
int shrink_axis_mask; |
| 410 |
} TfLiteStridedSliceParams; |
| 411 |
|
| 412 |
typedef struct { |
| 413 |
TfLiteType output_type; |
| 414 |
} TfLiteArgMaxParams; |
| 415 |
|
| 416 |
typedef struct { |
| 417 |
TfLiteType output_type; |
| 418 |
} TfLiteArgMinParams; |
| 419 |
|
| 420 |
typedef struct { |
| 421 |
// Parameters supported by version 1: |
| 422 |
TfLitePadding padding; |
| 423 |
int stride_width; |
| 424 |
int stride_height; |
| 425 |
|
| 426 |
// Parameters supported by version 4: |
| 427 |
TfLiteFusedActivation activation; |
| 428 |
} TfLiteTransposeConvParams; |
| 429 |
|
| 430 |
typedef struct { |
| 431 |
bool validate_indices; |
| 432 |
} TfLiteSparseToDenseParams; |
| 433 |
|
| 434 |
typedef struct { |
| 435 |
TfLiteType out_type; |
| 436 |
} TfLiteShapeParams; |
| 437 |
|
| 438 |
typedef struct { |
| 439 |
EmptyStructPlaceholder placeholder; |
| 440 |
} TfLiteRankParams; |
| 441 |
|
| 442 |
typedef struct { |
| 443 |
// Parameters supported by version 1: |
| 444 |
float min; |
| 445 |
float max; |
| 446 |
int num_bits; |
| 447 |
|
| 448 |
// Parameters supported by version 2: |
| 449 |
bool narrow_range; |
| 450 |
} TfLiteFakeQuantParams; |
| 451 |
|
| 452 |
typedef struct { |
| 453 |
int values_count; |
| 454 |
int axis; |
| 455 |
} TfLitePackParams; |
| 456 |
|
| 457 |
typedef struct { |
| 458 |
int axis; |
| 459 |
} TfLiteOneHotParams; |
| 460 |
|
| 461 |
typedef struct { |
| 462 |
int num; |
| 463 |
int axis; |
| 464 |
} TfLiteUnpackParams; |
| 465 |
|
| 466 |
typedef struct { |
| 467 |
float alpha; |
| 468 |
} TfLiteLeakyReluParams; |
| 469 |
|
| 470 |
typedef struct { |
| 471 |
TfLiteType index_out_type; |
| 472 |
} TfLiteUniqueParams; |
| 473 |
|
| 474 |
typedef struct { |
| 475 |
int seq_dim; |
| 476 |
int batch_dim; |
| 477 |
} TfLiteReverseSequenceParams; |
| 478 |
|
| 479 |
typedef struct { |
| 480 |
EmptyStructPlaceholder placeholder; |
| 481 |
} TfLiteMatrixDiagParams; |
| 482 |
|
| 483 |
typedef struct { |
| 484 |
EmptyStructPlaceholder placeholder; |
| 485 |
} TfLiteMatrixSetDiagParams; |
| 486 |
|
| 487 |
typedef struct { |
| 488 |
int then_subgraph_index; |
| 489 |
int else_subgraph_index; |
| 490 |
} TfLiteIfParams; |
| 491 |
|
| 492 |
typedef struct { |
| 493 |
int cond_subgraph_index; |
| 494 |
int body_subgraph_index; |
| 495 |
} TfLiteWhileParams; |
| 496 |
|
| 497 |
typedef struct { |
| 498 |
bool exclusive; |
| 499 |
bool reverse; |
| 500 |
} TfLiteCumsumParams; |
| 501 |
|
| 502 |
typedef struct { |
| 503 |
int init_subgraph_index; |
| 504 |
} TfLiteCallOnceParams; |
| 505 |
|
| 506 |
typedef struct { |
| 507 |
int table_id; |
| 508 |
TfLiteType key_dtype; |
| 509 |
TfLiteType value_dtype; |
| 510 |
} TfLiteHashtableParams; |
| 511 |
|
| 512 |
typedef struct { |
| 513 |
const char* container; |
| 514 |
const char* shared_name; |
| 515 |
} TfLiteVarHandleParams; |
| 516 |
|
| 517 |
typedef struct { |
| 518 |
int seed; |
| 519 |
int seed2; |
| 520 |
} TfLiteRandomParams; |
| 521 |
|
| 522 |
typedef struct { |
| 523 |
int num_boundaries; |
| 524 |
// This points to the memory stored in the model (flatbuffer), |
| 525 |
// and is not owned. |
| 526 |
const float* boundaries; |
| 527 |
} TfLiteBucketizeParams; |
| 528 |
|
| 529 |
typedef struct { |
| 530 |
bool approximate; |
| 531 |
} TfLiteGeluParams; |
| 532 |
|
| 533 |
#ifdef __cplusplus |
| 534 |
} // extern "C" |
| 535 |
#endif // __cplusplus |
| 536 |
|
| 537 |
#endif // TENSORFLOW_LITE_CORE_C_BUILTIN_OP_DATA_H_ |