Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TensorFlow export compute graph to XML, JSON, etc

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?

like image 575
ignorance Avatar asked Feb 06 '23 08:02

ignorance


1 Answers

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)
like image 137
mrry Avatar answered Feb 07 '23 21:02

mrry