TensorFlow将计算图导出为XML,JSON等 [英] TensorFlow export compute graph to XML, JSON, etc

查看:749
本文介绍了TensorFlow将计算图导出为XML,JSON等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将TensorFlow计算图导出为XML或类似的东西,因此我可以使用外部程序修改它,然后重新导入。我发现 Meta Graph ,但是这种二进制格式导出,

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 exports in a binary format which I wouldn't know how to modify.

这样的能力是否存在?

推荐答案

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

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).

如果有是您的目标语言没有协议缓冲区实现,您可以从Python协议缓冲区对象生成JSON。例如,以下生成一个包含 GraphDef 的JSON表示形式的字符串:

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)

这篇关于TensorFlow将计算图导出为XML,JSON等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆