• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: 27.
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  // Name of the control outputs.
151  repeated string control_output_arrays = 24;
152
153  // If true, the model accepts an arbitrary batch size. Mutually exclusive with
154  // the 'batch' field: at most one of these two fields can be set.
155  optional bool variable_batch = 10;
156
157  repeated RnnState rnn_states = 12;
158
159  // Checks applied to the model, typically after toco's comprehensive
160  // graph transformations.
161  // Next ID to USE: 4.
162  message ModelCheck {
163    // Use the name of a type of operator to check its counts.
164    // Use "Total" for overall operator counts.
165    // Use "Arrays" for overall array counts.
166    optional string count_type = 1 [default = "None"];
167    // A count of zero is a meaningful check, so negative used to mean disable.
168    optional int32 count_min = 2 [default = -1];
169    // If count_max < count_min, then count_min is only allowed value.
170    optional int32 count_max = 3 [default = -1];
171  }
172  repeated ModelCheck model_checks = 14;
173
174  // If true, will allow passing inexistent arrays in --input_arrays
175  // and --output_arrays. This makes little sense, is only useful to
176  // more easily get graph visualizations.
177  optional bool allow_nonexistent_arrays = 16;
178
179  // If true, will allow passing non-ascii-printable characters in
180  // --input_arrays and --output_arrays. By default (if false), only
181  // ascii printable characters are allowed, i.e. character codes
182  // ranging from 32 to 127. This is disallowed by default so as to
183  // catch common copy-and-paste issues where invisible unicode
184  // characters are unwittingly added to these strings.
185  optional bool allow_nonascii_arrays = 17;
186
187  // If set, this ArraysExtraInfo allows to pass extra information about arrays
188  // not specified in the input model file, such as extra MinMax information.
189  optional ArraysExtraInfo arrays_extra_info = 18;
190
191  // When set to false, toco will not change the input ranges and the output
192  // ranges of concat operator to the overlap of all input ranges.
193  optional bool change_concat_input_ranges = 19 [default = true];
194
195  // Filepath of the saved model to be converted. This value will be non-empty
196  // only when the saved model import path will be used. Otherwise, the graph
197  // def-based conversion will be processed.
198  optional string saved_model_dir = 20;
199
200  // SavedModel file format version of The saved model file to be converted.
201  // This value will be set only when the SavedModel import path will be used.
202  optional int32 saved_model_version = 21;
203
204  // Set of string saved model tags, formatted in the comma-separated value.
205  // This value will be set only when the SavedModel import path will be used.
206  repeated string saved_model_tags = 22;
207
208  // Names to be exported (default: export all) when the saved model import path
209  // is on. This value will be set only when the SavedModel import path will be
210  // used.
211  repeated string saved_model_exported_names = 23;
212
213  // Whether or not to use hlo import.
214  optional bool use_hlo_import = 25;
215
216  // The hlo file type enum.
217  enum HloFileType {
218    UNKNOWN = 0;
219    HLO_TEXT = 1;
220    HLO_PROTO = 2;
221  }
222
223  // Hlo file type, this will be used for hlo import.
224  optional HloFileType hlo_file_type = 26;
225}
226