【发布时间】:2017-01-10 18:04:05
【问题描述】:
我想将 TensorFlow 计算图导出为 XML 或类似的东西,这样我就可以使用外部程序对其进行修改,然后重新导入它。我找到了Meta Graph,但它以二进制格式导出,我不知道如何修改。
这种能力存在吗?
【问题讨论】:
标签: json xml tensorflow export
我想将 TensorFlow 计算图导出为 XML 或类似的东西,这样我就可以使用外部程序对其进行修改,然后重新导入它。我找到了Meta Graph,但它以二进制格式导出,我不知道如何修改。
这种能力存在吗?
【问题讨论】:
标签: json xml tensorflow export
TensorFlow 数据流图的原生序列化格式使用protocol buffers,它具有多种不同语言的绑定。您可以生成应该能够解析来自两个消息模式的二进制数据的代码:tensorflow.GraphDef(较低级别的表示)和 tensorflow.MetaGraphDef(较高级别的表示,其中包括 GraphDef 和其他关于如何解释图中的一些节点)。
如果您的目标语言没有协议缓冲区实现,您可以从 Python 协议缓冲区对象生成 JSON。例如,下面会生成一个包含GraphDef 的 JSON 表示形式的字符串:
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)
【讨论】:
graph_def = tf.GraphDef(); json_format.Parse(json_string, graph_def)