• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1syntax = "proto3";
2
3package tensorflow;
4option cc_enable_arenas = true;
5option java_outer_classname = "MetaGraphProtos";
6option java_multiple_files = true;
7option java_package = "org.tensorflow.framework";
8option go_package = "github.com/tensorflow/tensorflow/tensorflow/go/core/protobuf";
9import "google/protobuf/any.proto";
10
11import "tensorflow/core/framework/graph.proto";
12import "tensorflow/core/framework/op_def.proto";
13import "tensorflow/core/framework/tensor_shape.proto";
14import "tensorflow/core/framework/types.proto";
15import "tensorflow/core/protobuf/saved_object_graph.proto";
16import "tensorflow/core/protobuf/saver.proto";
17
18// NOTE: This protocol buffer is evolving, and will go through revisions in the
19// coming months.
20//
21// Protocol buffer containing the following which are necessary to restart
22// training, run inference. It can be used to serialize/de-serialize memory
23// objects necessary for running computation in a graph when crossing the
24// process boundary. It can be used for long term storage of graphs,
25// cross-language execution of graphs, etc.
26//   MetaInfoDef
27//   GraphDef
28//   SaverDef
29//   CollectionDef
30//   TensorInfo
31//   SignatureDef
32message MetaGraphDef {
33  // Meta information regarding the graph to be exported.  To be used by users
34  // of this protocol buffer to encode information regarding their meta graph.
35  message MetaInfoDef {
36    // User specified Version string. Can be the name of the model and revision,
37    // steps this model has been trained to, etc.
38    string meta_graph_version = 1;
39
40    // A copy of the OpDefs used by the producer of this graph_def.
41    // Descriptions and Ops not used in graph_def are stripped out.
42    OpList stripped_op_list = 2;
43
44    // A serialized protobuf. Can be the time this meta graph is created, or
45    // modified, or name of the model.
46    google.protobuf.Any any_info = 3;
47
48    // User supplied tag(s) on the meta_graph and included graph_def.
49    //
50    // MetaGraphDefs should be tagged with their capabilities or use-cases.
51    // Examples: "train", "serve", "gpu", "tpu", etc.
52    // These tags enable loaders to access the MetaGraph(s) appropriate for a
53    // specific use-case or runtime environment.
54    repeated string tags = 4;
55
56    // The __version__ string of the tensorflow build used to write this graph.
57    // This will be populated by the framework, which will overwrite any user
58    // supplied value.
59    string tensorflow_version = 5;
60
61    // The __git_version__ string of the tensorflow build used to write this
62    // graph. This will be populated by the framework, which will overwrite any
63    // user supplied value.
64    string tensorflow_git_version = 6;
65
66    // A flag to denote whether default-valued attrs have been stripped from
67    // the nodes in this graph_def.
68    bool stripped_default_attrs = 7;
69  }
70  MetaInfoDef meta_info_def = 1;
71
72  // GraphDef.
73  GraphDef graph_def = 2;
74
75  // SaverDef.
76  SaverDef saver_def = 3;
77
78  // collection_def: Map from collection name to collections.
79  // See CollectionDef section for details.
80  map<string, CollectionDef> collection_def = 4;
81
82  // signature_def: Map from user supplied key for a signature to a single
83  // SignatureDef.
84  map<string, SignatureDef> signature_def = 5;
85
86  // Asset file def to be used with the defined graph.
87  repeated AssetFileDef asset_file_def = 6;
88
89  // Extra information about the structure of functions and stateful objects.
90  SavedObjectGraph object_graph_def = 7;
91}
92
93// CollectionDef should cover most collections.
94// To add a user-defined collection, do one of the following:
95// 1. For simple data types, such as string, int, float:
96//      tf.add_to_collection("your_collection_name", your_simple_value)
97//    strings will be stored as bytes_list.
98//
99// 2. For Protobuf types, there are three ways to add them:
100//    1) tf.add_to_collection("your_collection_name",
101//         your_proto.SerializeToString())
102//
103//       collection_def {
104//         key: "user_defined_bytes_collection"
105//         value {
106//           bytes_list {
107//             value: "queue_name: \"test_queue\"\n"
108//           }
109//         }
110//       }
111//
112//  or
113//
114//    2) tf.add_to_collection("your_collection_name", str(your_proto))
115//
116//       collection_def {
117//         key: "user_defined_string_collection"
118//         value {
119//          bytes_list {
120//             value: "\n\ntest_queue"
121//           }
122//         }
123//       }
124//
125//  or
126//
127//    3) any_buf = any_pb2.Any()
128//       tf.add_to_collection("your_collection_name",
129//         any_buf.Pack(your_proto))
130//
131//       collection_def {
132//         key: "user_defined_any_collection"
133//         value {
134//           any_list {
135//             value {
136//               type_url: "type.googleapis.com/tensorflow.QueueRunnerDef"
137//               value: "\n\ntest_queue"
138//             }
139//           }
140//         }
141//       }
142//
143// 3. For Python objects, implement to_proto() and from_proto(), and register
144//    them in the following manner:
145//    ops.register_proto_function("your_collection_name",
146//                                proto_type,
147//                                to_proto=YourPythonObject.to_proto,
148//                                from_proto=YourPythonObject.from_proto)
149//    These functions will be invoked to serialize and de-serialize the
150//    collection. For example,
151//    ops.register_proto_function(ops.GraphKeys.GLOBAL_VARIABLES,
152//                                proto_type=variable_pb2.VariableDef,
153//                                to_proto=Variable.to_proto,
154//                                from_proto=Variable.from_proto)
155message CollectionDef {
156  // NodeList is used for collecting nodes in graph. For example
157  // collection_def {
158  //   key: "summaries"
159  //   value {
160  //     node_list {
161  //       value: "input_producer/ScalarSummary:0"
162  //       value: "shuffle_batch/ScalarSummary:0"
163  //       value: "ImageSummary:0"
164  //     }
165  //   }
166  message NodeList {
167    repeated string value = 1;
168  }
169
170  // BytesList is used for collecting strings and serialized protobufs. For
171  // example:
172  // collection_def {
173  //   key: "trainable_variables"
174  //   value {
175  //     bytes_list {
176  //       value: "\n\017conv1/weights:0\022\024conv1/weights/Assign
177  //              \032\024conv1/weights/read:0"
178  //       value: "\n\016conv1/biases:0\022\023conv1/biases/Assign\032
179  //              \023conv1/biases/read:0"
180  //     }
181  //   }
182  // }
183  message BytesList {
184    repeated bytes value = 1;
185  }
186
187  // Int64List is used for collecting int, int64 and long values.
188  message Int64List {
189    repeated int64 value = 1 [packed = true];
190  }
191
192  // FloatList is used for collecting float values.
193  message FloatList {
194    repeated float value = 1 [packed = true];
195  }
196
197  // AnyList is used for collecting Any protos.
198  message AnyList {
199    repeated google.protobuf.Any value = 1;
200  }
201
202  oneof kind {
203    NodeList node_list = 1;
204    BytesList bytes_list = 2;
205    Int64List int64_list = 3;
206    FloatList float_list = 4;
207    AnyList any_list = 5;
208  }
209}
210
211// Information about a Tensor necessary for feeding or retrieval.
212message TensorInfo {
213  // For sparse tensors, The COO encoding stores a triple of values, indices,
214  // and shape.
215  message CooSparse {
216    // The shape of the values Tensor is [?].  Its dtype must be the dtype of
217    // the SparseTensor as a whole, given in the enclosing TensorInfo.
218    string values_tensor_name = 1;
219
220    // The indices Tensor must have dtype int64 and shape [?, ?].
221    string indices_tensor_name = 2;
222
223    // The dynamic logical shape represented by the SparseTensor is recorded in
224    // the Tensor referenced here.  It must have dtype int64 and shape [?].
225    string dense_shape_tensor_name = 3;
226  }
227
228  oneof encoding {
229    // For dense `Tensor`s, the name of the tensor in the graph.
230    string name = 1;
231    // There are many possible encodings of sparse matrices
232    // (https://en.wikipedia.org/wiki/Sparse_matrix).  Currently, TensorFlow
233    // uses only the COO encoding.  This is supported and documented in the
234    // SparseTensor Python class.
235    CooSparse coo_sparse = 4;
236  }
237  DataType dtype = 2;
238  // The static shape should be recorded here, to the extent that it can
239  // be known in advance.  In the case of a SparseTensor, this field describes
240  // the logical shape of the represented tensor (aka dense_shape).
241  TensorShapeProto tensor_shape = 3;
242}
243
244// SignatureDef defines the signature of a computation supported by a TensorFlow
245// graph.
246//
247// For example, a model with two loss computations, sharing a single input,
248// might have the following signature_def map.
249//
250// Note that across the two SignatureDefs "loss_A" and "loss_B", the input key,
251// output key, and method_name are identical, and will be used by system(s) that
252// implement or rely upon this particular loss method. The output tensor names
253// differ, demonstrating how different outputs can exist for the same method.
254//
255// signature_def {
256//   key: "loss_A"
257//   value {
258//     inputs {
259//       key: "input"
260//       value {
261//         name: "input:0"
262//         dtype: DT_STRING
263//         tensor_shape: ...
264//       }
265//     }
266//     outputs {
267//       key: "loss_output"
268//       value {
269//         name: "loss_output_A:0"
270//         dtype: DT_FLOAT
271//         tensor_shape: ...
272//       }
273//     }
274//   }
275//   ...
276//   method_name: "some/package/compute_loss"
277// }
278// signature_def {
279//   key: "loss_B"
280//   value {
281//     inputs {
282//       key: "input"
283//       value {
284//         name: "input:0"
285//         dtype: DT_STRING
286//         tensor_shape: ...
287//       }
288//     }
289//     outputs {
290//       key: "loss_output"
291//       value {
292//         name: "loss_output_B:0"
293//         dtype: DT_FLOAT
294//         tensor_shape: ...
295//       }
296//     }
297//   }
298//   ...
299//   method_name: "some/package/compute_loss"
300// }
301message SignatureDef {
302  // Named input parameters.
303  map<string, TensorInfo> inputs = 1;
304  // Named output parameters.
305  map<string, TensorInfo> outputs = 2;
306  // Extensible method_name information enabling third-party users to mark a
307  // SignatureDef as supporting a particular method. This enables producers and
308  // consumers of SignatureDefs, e.g. a model definition library and a serving
309  // library to have a clear hand-off regarding the semantics of a computation.
310  //
311  // Note that multiple SignatureDefs in a single MetaGraphDef may have the same
312  // method_name. This is commonly used to support multi-headed computation,
313  // where a single graph computation may return multiple results.
314  string method_name = 3;
315}
316
317// An asset file def for a single file or a set of sharded files with the same
318// name.
319message AssetFileDef {
320  // The tensor to bind the asset filename to.
321  TensorInfo tensor_info = 1;
322  // The filename within an assets directory. Note: does not include the path
323  // prefix, i.e. directories. For an asset at /tmp/path/vocab.txt, the filename
324  // would be "vocab.txt".
325  string filename = 2;
326}
327