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/lite/toco/types.proto"; 16 17package toco; 18 19message InputArrayShape { 20 repeated int32 dims = 2; 21} 22 23// Next ID to USE: 7. 24message InputArray { 25 // Name of the input arrays, i.e. the arrays from which input activations 26 // will be read. 27 optional string name = 1; 28 29 // Shape of the input. For many applications the dimensions are {batch, 30 // height, width, depth}. Often the batch is left "unspecified" by providing 31 // a value of -1. 32 // 33 // The last dimension is typically called 'depth' or 'channels'. For example, 34 // for an image model taking RGB images as input, this would have the value 3. 35 optional InputArrayShape shape = 6; 36 37 // mean_value and std_value parameters control the interpretation of raw input 38 // activation values (elements of the input array) as real numbers. The 39 // mapping is given by: 40 // 41 // real_value = (raw_input_value - mean_value) / std_value 42 // 43 // In particular, the defaults (mean_value=0, std_value=1) yield 44 // real_value = raw_input_value. Often, non-default values are used in image 45 // models. For example, an image model taking uint8 image channel values as 46 // its raw inputs, in [0, 255] range, may use mean_value=128, std_value=128 to 47 // map them into the interval [-1, 1). 48 // 49 // Note: this matches exactly the meaning of mean_value and std_value in 50 // (TensorFlow via LegacyFedInput). 51 optional float mean_value = 3; 52 optional float std_value = 4 [default = 1.]; 53 54 // Data type of the input. 55 // 56 // In many graphs, the input arrays already have defined data types, 57 // e.g. Placeholder nodes in a TensorFlow GraphDef have a dtype attribute. 58 // In those cases, it is not needed to specify this data_type flag. 59 // The purpose of this flag is only to define the data type of input 60 // arrays whose type isn't defined in the input graph file. For example, 61 // when specifying an arbitrary (not Placeholder) --input_array into 62 // a TensorFlow GraphDef. 63 // 64 // When this data_type is quantized (e.g. QUANTIZED_UINT8), the 65 // corresponding quantization parameters are the mean_value, std_value 66 // fields. 67 // 68 // It is also important to understand the nuance between this data_type 69 // flag and the inference_input_type in TocoFlags. The basic difference 70 // is that this data_type (like all ModelFlags) describes a property 71 // of the input graph, while inference_input_type (like all TocoFlags) 72 // describes an aspect of the toco transformation process and thus of 73 // the output file. The types of input arrays may be different between 74 // the input and output files if quantization or dequantization occurred. 75 // Such differences can only occur for real-number data i.e. only 76 // between FLOAT and quantized types (e.g. QUANTIZED_UINT8). 77 optional IODataType data_type = 5; 78} 79 80message RnnState { 81 optional string state_array = 1; 82 optional string back_edge_source_array = 2; 83 optional bool discardable = 5; 84 // size allows to specify a 1-D shape for the RNN state array. 85 // Will be expanded with 1's to fit the model. 86 // TODO(benoitjacob): should allow a generic, explicit shape. 87 optional int32 size = 3; 88 optional int32 num_dims = 4; 89} 90 91// An ArraysExtraInfo message stores a collection of additional Information 92// about arrays in a model, complementing the information in the model itself. 93// It is intentionally a separate message so that it may be serialized and 94// passed separately from the model. See --arrays_extra_info_file. 95// 96// A typical use case is to manually specify MinMax for specific arrays in a 97// model that does not already contain such MinMax information. 98message ArraysExtraInfo { 99 message Entry { 100 // Next ID to use: 8. 101 optional string name = 1; 102 optional string name_regexp = 7; 103 optional double min = 2; 104 optional double max = 3; 105 optional IODataType data_type = 4; 106 optional InputArrayShape shape = 5; 107 optional float constant_float_value = 6; 108 } 109 repeated Entry entries = 1; 110} 111 112// ModelFlags encodes properties of a model that, depending on the file 113// format, may or may not be recorded in the model file. The purpose of 114// representing these properties in ModelFlags is to allow passing them 115// separately from the input model file, for instance as command-line 116// parameters, so that we can offer a single uniform interface that can 117// handle files from different input formats. 118// 119// For each of these properties, and each supported file format, we 120// detail in comments below whether the property exists in the given file 121// format. 122// 123// Obsolete flags that have been removed: 124// optional int32 input_depth = 3; 125// optional int32 input_width = 4; 126// optional int32 input_height = 5; 127// optional int32 batch = 6 [ default = 1]; 128// optional float mean_value = 7; 129// optional float std_value = 8 [default = 1.]; 130// optional int32 input_dims = 11 [ default = 4]; 131// repeated int32 input_shape = 13; 132// 133// Next ID to USE: 20. 134message ModelFlags { 135 // Information about the input arrays, i.e. the arrays from which input 136 // activations will be read. 137 repeated InputArray input_arrays = 1; 138 139 // Name of the output arrays, i.e. the arrays into which output activations 140 // will be written. 141 repeated string output_arrays = 2; 142 143 // If true, the model accepts an arbitrary batch size. Mutually exclusive with 144 // the 'batch' field: at most one of these two fields can be set. 145 optional bool variable_batch = 10; 146 147 repeated RnnState rnn_states = 12; 148 149 // Checks applied to the model, typically after toco's comprehensive 150 // graph transformations. 151 // Next ID to USE: 4. 152 message ModelCheck { 153 // Use the name of a type of operator to check its counts. 154 // Use "Total" for overall operator counts. 155 // Use "Arrays" for overall array counts. 156 optional string count_type = 1 [default = "None"]; 157 // A count of zero is a meaningful check, so negative used to mean disable. 158 optional int32 count_min = 2 [default = -1]; 159 // If count_max < count_min, then count_min is only allowed value. 160 optional int32 count_max = 3 [default = -1]; 161 } 162 repeated ModelCheck model_checks = 14; 163 164 // If true, will allow passing inexistent arrays in --input_arrays 165 // and --output_arrays. This makes little sense, is only useful to 166 // more easily get graph visualizations. 167 optional bool allow_nonexistent_arrays = 16; 168 169 // If true, will allow passing non-ascii-printable characters in 170 // --input_arrays and --output_arrays. By default (if false), only 171 // ascii printable characters are allowed, i.e. character codes 172 // ranging from 32 to 127. This is disallowed by default so as to 173 // catch common copy-and-paste issues where invisible unicode 174 // characters are unwittingly added to these strings. 175 optional bool allow_nonascii_arrays = 17; 176 177 // If set, this ArraysExtraInfo allows to pass extra information about arrays 178 // not specified in the input model file, such as extra MinMax information. 179 optional ArraysExtraInfo arrays_extra_info = 18; 180 181 // When set to false, toco will not change the input ranges and the output 182 // ranges of concat operator to the overlap of all input ranges. 183 optional bool change_concat_input_ranges = 19 [default = true]; 184} 185