TensorFlow export compute graph to XML, JSON, etc TensorFlow export compute graph to XML, JSON, etc json json

TensorFlow export compute graph to XML, JSON, etc


The native serialization format for TensorFlow's dataflow graph uses protocol buffers, which have bindings in many different languages. You can generate code that should be able to parse the binary data from the two message schemas: tensorflow.GraphDef (a lower-level representation) and tensorflow.MetaGraphDef (a higher-level representation, which includes a GraphDef and other information about how to interpret some of the nodes in the graph).

If there is no protocol buffer implementation for your target language, you can generate JSON from the Python protocol buffer object. For example, the following generates a string containing a JSON representation of a GraphDef:

import tensorflow as tffrom google.protobuf import json_formatwith tf.Graph().as_default() as graph:  # Add nodes to the graph...graph_def = graph.as_graph_def()json_string = json_format.MessageToJson(graph_def)