我想将 TensorFlow 计算图导出为 XML 或类似格式,以便我可以使用外部程序修改它,然后重新导入它。我找到了 Meta Graph但这以二进制格式导出,我不知道如何修改。
这种能力存在吗?
最佳答案
TensorFlow 数据流图的原生序列化格式使用 protocol buffers ,它有许多不同语言的绑定(bind)。您可以生成能够从两个消息模式中解析二进制数据的代码:tensorflow.GraphDef
(较低级别的表示)和 tensorflow.MetaGraphDef
(更高级别的表示,其中包括 GraphDef
和有关如何解释图中某些节点的其他信息)。
如果您的目标语言没有 Protocol Buffer 实现,您可以从 Python Protocol Buffer 对象生成 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)
关于json - TensorFlow 将计算图导出为 XML、JSON 等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41575442/