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// 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 // FunctionDef name to aliases mapping. 70 map<string, string> function_aliases = 8; 71 } 72 MetaInfoDef meta_info_def = 1; 73 74 // GraphDef. 75 GraphDef graph_def = 2; 76 77 // SaverDef. 78 SaverDef saver_def = 3; 79 80 // collection_def: Map from collection name to collections. 81 // See CollectionDef section for details. 82 map<string, CollectionDef> collection_def = 4; 83 84 // signature_def: Map from user supplied key for a signature to a single 85 // SignatureDef. 86 map<string, SignatureDef> signature_def = 5; 87 88 // Asset file def to be used with the defined graph. 89 repeated AssetFileDef asset_file_def = 6; 90 91 // Extra information about the structure of functions and stateful objects. 92 SavedObjectGraph object_graph_def = 7; 93} 94 95// CollectionDef should cover most collections. 96// To add a user-defined collection, do one of the following: 97// 1. For simple data types, such as string, int, float: 98// tf.add_to_collection("your_collection_name", your_simple_value) 99// strings will be stored as bytes_list. 100// 101// 2. For Protobuf types, there are three ways to add them: 102// 1) tf.add_to_collection("your_collection_name", 103// your_proto.SerializeToString()) 104// 105// collection_def { 106// key: "user_defined_bytes_collection" 107// value { 108// bytes_list { 109// value: "queue_name: \"test_queue\"\n" 110// } 111// } 112// } 113// 114// or 115// 116// 2) tf.add_to_collection("your_collection_name", str(your_proto)) 117// 118// collection_def { 119// key: "user_defined_string_collection" 120// value { 121// bytes_list { 122// value: "\n\ntest_queue" 123// } 124// } 125// } 126// 127// or 128// 129// 3) any_buf = any_pb2.Any() 130// tf.add_to_collection("your_collection_name", 131// any_buf.Pack(your_proto)) 132// 133// collection_def { 134// key: "user_defined_any_collection" 135// value { 136// any_list { 137// value { 138// type_url: "type.googleapis.com/tensorflow.QueueRunnerDef" 139// value: "\n\ntest_queue" 140// } 141// } 142// } 143// } 144// 145// 3. For Python objects, implement to_proto() and from_proto(), and register 146// them in the following manner: 147// ops.register_proto_function("your_collection_name", 148// proto_type, 149// to_proto=YourPythonObject.to_proto, 150// from_proto=YourPythonObject.from_proto) 151// These functions will be invoked to serialize and de-serialize the 152// collection. For example, 153// ops.register_proto_function(ops.GraphKeys.GLOBAL_VARIABLES, 154// proto_type=variable_pb2.VariableDef, 155// to_proto=Variable.to_proto, 156// from_proto=Variable.from_proto) 157message CollectionDef { 158 // NodeList is used for collecting nodes in graph. For example 159 // collection_def { 160 // key: "summaries" 161 // value { 162 // node_list { 163 // value: "input_producer/ScalarSummary:0" 164 // value: "shuffle_batch/ScalarSummary:0" 165 // value: "ImageSummary:0" 166 // } 167 // } 168 message NodeList { 169 repeated string value = 1; 170 } 171 172 // BytesList is used for collecting strings and serialized protobufs. For 173 // example: 174 // collection_def { 175 // key: "trainable_variables" 176 // value { 177 // bytes_list { 178 // value: "\n\017conv1/weights:0\022\024conv1/weights/Assign 179 // \032\024conv1/weights/read:0" 180 // value: "\n\016conv1/biases:0\022\023conv1/biases/Assign\032 181 // \023conv1/biases/read:0" 182 // } 183 // } 184 // } 185 message BytesList { 186 repeated bytes value = 1; 187 } 188 189 // Int64List is used for collecting int, int64 and long values. 190 message Int64List { 191 repeated int64 value = 1 [packed = true]; 192 } 193 194 // FloatList is used for collecting float values. 195 message FloatList { 196 repeated float value = 1 [packed = true]; 197 } 198 199 // AnyList is used for collecting Any protos. 200 message AnyList { 201 repeated google.protobuf.Any value = 1; 202 } 203 204 oneof kind { 205 NodeList node_list = 1; 206 BytesList bytes_list = 2; 207 Int64List int64_list = 3; 208 FloatList float_list = 4; 209 AnyList any_list = 5; 210 } 211} 212 213// Information about a Tensor necessary for feeding or retrieval. 214message TensorInfo { 215 // For sparse tensors, The COO encoding stores a triple of values, indices, 216 // and shape. 217 message CooSparse { 218 // The shape of the values Tensor is [?]. Its dtype must be the dtype of 219 // the SparseTensor as a whole, given in the enclosing TensorInfo. 220 string values_tensor_name = 1; 221 222 // The indices Tensor must have dtype int64 and shape [?, ?]. 223 string indices_tensor_name = 2; 224 225 // The dynamic logical shape represented by the SparseTensor is recorded in 226 // the Tensor referenced here. It must have dtype int64 and shape [?]. 227 string dense_shape_tensor_name = 3; 228 } 229 230 // Generic encoding for composite tensors. 231 message CompositeTensor { 232 // The serialized TypeSpec for the composite tensor. 233 TypeSpecProto type_spec = 1; 234 235 // A TensorInfo for each flattened component tensor. 236 repeated TensorInfo components = 2; 237 } 238 239 oneof encoding { 240 // For dense `Tensor`s, the name of the tensor in the graph. 241 string name = 1; 242 // There are many possible encodings of sparse matrices 243 // (https://en.wikipedia.org/wiki/Sparse_matrix). Currently, TensorFlow 244 // uses only the COO encoding. This is supported and documented in the 245 // SparseTensor Python class. 246 CooSparse coo_sparse = 4; 247 // Generic encoding for CompositeTensors. 248 CompositeTensor composite_tensor = 5; 249 } 250 DataType dtype = 2; 251 // The static shape should be recorded here, to the extent that it can 252 // be known in advance. In the case of a SparseTensor, this field describes 253 // the logical shape of the represented tensor (aka dense_shape). 254 TensorShapeProto tensor_shape = 3; 255} 256 257// SignatureDef defines the signature of a computation supported by a TensorFlow 258// graph. 259// 260// For example, a model with two loss computations, sharing a single input, 261// might have the following signature_def map, in a MetaGraphDef message. 262// 263// Note that across the two SignatureDefs "loss_A" and "loss_B", the input key, 264// output key, and method_name are identical, and will be used by system(s) that 265// implement or rely upon this particular loss method. The output tensor names 266// differ, demonstrating how different outputs can exist for the same method. 267// 268// signature_def { 269// key: "loss_A" 270// value { 271// inputs { 272// key: "input" 273// value { 274// name: "input:0" 275// dtype: DT_STRING 276// tensor_shape: ... 277// } 278// } 279// outputs { 280// key: "loss_output" 281// value { 282// name: "loss_output_A:0" 283// dtype: DT_FLOAT 284// tensor_shape: ... 285// } 286// } 287// method_name: "some/package/compute_loss" 288// } 289// ... 290// } 291// signature_def { 292// key: "loss_B" 293// value { 294// inputs { 295// key: "input" 296// value { 297// name: "input:0" 298// dtype: DT_STRING 299// tensor_shape: ... 300// } 301// } 302// outputs { 303// key: "loss_output" 304// value { 305// name: "loss_output_B:0" 306// dtype: DT_FLOAT 307// tensor_shape: ... 308// } 309// } 310// method_name: "some/package/compute_loss" 311// } 312// ... 313// } 314message SignatureDef { 315 // Named input parameters. 316 map<string, TensorInfo> inputs = 1; 317 // Named output parameters. 318 map<string, TensorInfo> outputs = 2; 319 // Extensible method_name information enabling third-party users to mark a 320 // SignatureDef as supporting a particular method. This enables producers and 321 // consumers of SignatureDefs, e.g. a model definition library and a serving 322 // library to have a clear hand-off regarding the semantics of a computation. 323 // 324 // Note that multiple SignatureDefs in a single MetaGraphDef may have the same 325 // method_name. This is commonly used to support multi-headed computation, 326 // where a single graph computation may return multiple results. 327 string method_name = 3; 328} 329 330// An asset file def for a single file or a set of sharded files with the same 331// name. 332message AssetFileDef { 333 // The tensor to bind the asset filename to. 334 TensorInfo tensor_info = 1; 335 // The filename within an assets directory. Note: does not include the path 336 // prefix, i.e. directories. For an asset at /tmp/path/vocab.txt, the filename 337 // would be "vocab.txt". 338 string filename = 2; 339} 340