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