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. 14syntax = "proto2"; 15import "tensorflow/contrib/lite/toco/types.proto"; 16 17package toco; 18 19// Supported I/O file formats. Some formats may be input-only or output-only. 20enum FileFormat { 21 FILE_FORMAT_UNKNOWN = 0; 22 23 // GraphDef, third_party/tensorflow/core/framework/graph.proto 24 TENSORFLOW_GRAPHDEF = 1; 25 26 // Tensorflow's mobile inference model. 27 // third_party/tensorflow/contrib/tflite/schema.fbs 28 TFLITE = 2; 29 30 // GraphViz 31 // Export-only. 32 GRAPHVIZ_DOT = 3; 33} 34 35// TocoFlags encodes extra parameters that drive tooling operations, that 36// are not normally encoded in model files and in general may not be thought 37// of as properties of models, instead describing how models are to be 38// processed in the context of the present tooling job. 39// Next Id: 13 40message TocoFlags { 41 // Input file format 42 optional FileFormat input_format = 1; 43 44 // Output file format 45 optional FileFormat output_format = 2; 46 47 // Similar to inference_type, but allows to control specifically the 48 // quantization of input arrays, separately from other arrays. 49 // 50 // If not set, then the value of inference_type is implicitly used, i.e. 51 // by default input arrays are quantized like other arrays. 52 // 53 // Like inference_type, this only affects real-number arrays. By "real-number" 54 // we mean float arrays, and quantized arrays. This excludes plain 55 // integer arrays, strings arrays, and every other data type. 56 // 57 // The typical use for this flag is for vision models taking a bitmap 58 // as input, typically with uint8 channels, yet still requiring floating-point 59 // inference. For such image models, the uint8 input is quantized, i.e. 60 // the uint8 values are interpreted as real numbers, and the quantization 61 // parameters used for such input arrays are their mean_value, std_value 62 // parameters. 63 optional IODataType inference_input_type = 11; 64 65 // Sets the type of real-number arrays in the output file, that is, controls 66 // the representation (quantization) of real numbers in the output file, 67 // except for input arrays, which are controlled by inference_input_type. 68 // 69 // NOTE: this flag only impacts real-number arrays. By "real-number" 70 // we mean float arrays, and quantized arrays. This excludes plain 71 // integer arrays, strings arrays, and every other data type. 72 // 73 // For real-number arrays, the impact of this flag is to allow the output 74 // file to choose a different real-numbers representation (quantization) 75 // from what the input file used. For any other types of arrays, changing 76 // the data type would not make sense. 77 // 78 // Specifically: 79 // - If FLOAT, then real-numbers arrays will be of type float in 80 // the output file. If they were quantized in the input file, then 81 // they get dequantized. 82 // - If QUANTIZED_UINT8, then real-numbers arrays will be quantized 83 // as uint8 in the output file. If they were float in the input file, 84 // then they get quantized. 85 // - If not set, then all real-numbers arrays retain the same type in the 86 // output file as they have in the input file. 87 // 88 optional IODataType inference_type = 4; 89 90 // default_ranges_min and default_ranges_max are helpers to experiment 91 // with quantization of models. Normally, quantization requires the input 92 // model to have (min, max) range information for every activations array. 93 // This is needed in order to know how to quantize arrays and still achieve 94 // satisfactory accuracy. However, in some circumstances one would just like 95 // to estimate the performance of quantized inference, without caring about 96 // accuracy. That is what default_ranges_min and default_ranges_max are for: 97 // when specified, they will be used as default (min, max) range boundaries 98 // for all activation arrays that lack (min, max) range information, thus 99 // allowing for quantization to proceed. 100 // 101 // It should be clear from the above explanation that these parameters are 102 // for experimentation purposes only and should not be used in production: 103 // they make it easy to quantize models, but the resulting quantized model 104 // will be inaccurate. 105 optional float default_ranges_min = 5; 106 optional float default_ranges_max = 6; 107 108 // Ignore and discard FakeQuant nodes. For instance, that can be used to 109 // generate plain float code without fake-quantization from a quantized 110 // graph. 111 optional bool drop_fake_quant = 7; 112 113 // Normally, FakeQuant nodes must be strict boundaries for graph 114 // transformations, in order to ensure that quantized inference has the 115 // exact same arithmetic behavior as quantized training --- which is the 116 // whole point of quantized training and of FakeQuant nodes in the first 117 // place. However, that entails subtle requirements on where exactly 118 // FakeQuant nodes must be placed in the graph. Some quantized graphs 119 // have FakeQuant nodes at unexpected locations, that prevent graph 120 // transformations that are necessary in order to generate inference 121 // code for these graphs. Such graphs should be fixed, but as a 122 // temporary work-around, setting this reorder_across_fake_quant flag 123 // allows toco to perform necessary graph transformaitons on them, 124 // at the cost of no longer faithfully matching inference and training 125 // arithmetic. 126 optional bool reorder_across_fake_quant = 8; 127 128 // If true, allow TOCO to create TF Lite Custom operators for all the 129 // unsupported Tensorflow ops. 130 optional bool allow_custom_ops = 10; 131 132 // Applies only to the case when the input format is TENSORFLOW_GRAPHDEF. 133 // If true, then control dependencies will be immediately dropped during 134 // import. 135 // If not set, the default behavior is as follows: 136 // - Default to false if the output format is TENSORFLOW_GRAPHDEF. 137 // - Default to true in all other cases. 138 optional bool drop_control_dependency = 12; 139} 140