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