json - TensorFlow 将计算图导出为 XML、JSON 等

标签 json xml tensorflow export

我想将 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/

相关文章:

iphone - 如何在 Objective-C 中创建一个 json 字符串?

javascript - asp.net中发送复杂数据和JSON问题

javascript - 巴别塔 : duplicate plugin/preset error detected

php - 将推文存储到数据库中的简单方法是什么?

Python Tensorflow 训练-值错误 : Tensor must be from the same graph as Tensor

javascript - 使用 CanvasJS 动态确定要显示的饼图数量并在单个页面上显示每个饼图

xml - namespace URI 中尾部斜线的意义是什么?

python - 继承 ElementTree 解析器以保留注释

python - tf.keras.model 的 add_loss 方法的文档

python - 如何解决 "ValueError: A ` Concatenate` 层需要具有匹配形状的输入(除了连接轴之外)”?