TensorFlow将计算图导出为XML,JSON等

aid*_*ald 3 xml json export tensorflow

我想将TensorFlow计算图导出为XML或类似的东西,以便我可以使用外部程序对其进行修改,然后重新导入它.我找到了Meta Graph,但这是以二进制格式导出的,我不知道如何修改.

这种能力是否存在?

mrr*_*rry 6

TensorFlow数据流图的本机序列化格式使用协议缓冲区,它具有许多不同语言的绑定.您可以生成应该能够从两个消息模式中解析二进制数据的代码:( tensorflow.GraphDef较低级别的表示)和tensorflow.MetaGraphDef(较高级别的表示,其中包括GraphDef有关如何解释其中某些节点的信息和其他信息).图形).

如果目标语言没有协议缓冲区实现,则可以从Python协议缓冲区对象生成JSON.例如,以下代码生成一个包含以下JSON表示形式的字符串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)
Run Code Online (Sandbox Code Playgroud)