• 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";
15import "tensorflow/contrib/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}
89
90// An ArraysExtraInfo message stores a collection of additional Information
91// about arrays in a model, complementing the information in the model itself.
92// It is intentionally a separate message so that it may be serialized and
93// passed separately from the model. See --arrays_extra_info_file.
94//
95// A typical use case is to manually specify MinMax for specific arrays in a
96// model that does not already contain such MinMax information.
97message ArraysExtraInfo {
98  message Entry {
99    optional string name = 1;
100    optional float min = 2;
101    optional float max = 3;
102  }
103  repeated Entry entries = 1;
104}
105
106// ModelFlags encodes properties of a model that, depending on the file
107// format, may or may not be recorded in the model file. The purpose of
108// representing these properties in ModelFlags is to allow passing them
109// separately from the input model file, for instance as command-line
110// parameters, so that we can offer a single uniform interface that can
111// handle files from different input formats.
112//
113// For each of these properties, and each supported file format, we
114// detail in comments below whether the property exists in the given file
115// format.
116//
117// Obsolete flags that have been removed:
118//   optional int32 input_depth = 3;
119//   optional int32 input_width = 4;
120//   optional int32 input_height = 5;
121//   optional int32 batch = 6 [ default = 1];
122//   optional float mean_value = 7;
123//   optional float std_value = 8 [default = 1.];
124//   optional int32 input_dims = 11 [ default = 4];
125//   repeated int32 input_shape = 13;
126//
127// Next ID to USE: 19.
128message ModelFlags {
129  // Information about the input arrays, i.e. the arrays from which input
130  // activations will be read.
131  repeated InputArray input_arrays = 1;
132
133  // Name of the output arrays, i.e. the arrays into which output activations
134  // will be written.
135  repeated string output_arrays = 2;
136
137  // If true, the model accepts an arbitrary batch size. Mutually exclusive with
138  // the 'batch' field: at most one of these two fields can be set.
139  optional bool variable_batch = 10;
140
141  repeated RnnState rnn_states = 12;
142
143  // Checks applied to the model, typically after toco's comprehensive
144  // graph transformations.
145  // Next ID to USE: 4.
146  message ModelCheck {
147    // Use the name of a type of operator to check its counts.
148    // Use "Total" for overall operator counts.
149    // Use "Arrays" for overall array counts.
150    optional string count_type = 1 [default = "None"];
151    // A count of zero is a meaningful check, so negative used to mean disable.
152    optional int32 count_min = 2 [default = -1];
153    // If count_max < count_min, then count_min is only allowed value.
154    optional int32 count_max = 3 [default = -1];
155  }
156  repeated ModelCheck model_checks = 14;
157
158  // If true, will allow passing inexistent arrays in --input_arrays
159  // and --output_arrays. This makes little sense, is only useful to
160  // more easily get graph visualizations.
161  optional bool allow_nonexistent_arrays = 16;
162
163  // If true, will allow passing non-ascii-printable characters in
164  // --input_arrays and --output_arrays. By default (if false), only
165  // ascii printable characters are allowed, i.e. character codes
166  // ranging from 32 to 127. This is disallowed by default so as to
167  // catch common copy-and-paste issues where invisible unicode
168  // characters are unwittingly added to these strings.
169  optional bool allow_nonascii_arrays = 17;
170
171  // If set, this ArraysExtraInfo allows to pass extra information about arrays
172  // not specified in the input model file, such as extra MinMax information.
173  optional ArraysExtraInfo arrays_extra_info = 18;
174}
175