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