TensorFlow export compute graph to XML, JSON, etc

前端 未结 1 1503
被撕碎了的回忆
被撕碎了的回忆 2020-12-17 04:26

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 export

相关标签:
1条回答
  • 2020-12-17 04:56

    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)
    
    0 讨论(0)
提交回复
热议问题