I want to export a TensorFlow compute graph to XML or something similar so I can modify it with an external program and then re-import it. I found Meta Graph but this exports in a binary format which I wouldn't know how to modify.
Does such capability exist?
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 tf
from google.protobuf import json_format
with tf.Graph().as_default() as graph:
# Add nodes to the graph...
graph_def = graph.as_graph_def()
json_string = json_format.MessageToJson(graph_def)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With