TensorFlow数据流图的本机序列化格式使用协议缓冲区,该缓冲区具有许多不同语言的绑定。您可以生成代码,该代码应能够从以下两种消息模式中解析二进制数据:(
tensorflow.GraphDef一个较低级别的表示形式)和
tensorflow.metaGraphDef(一个较高级别的表示形式,其中包括
GraphDef有关如何解释节点中某些节点的信息)。图形)。
如果目标语言没有协议缓冲区实现,则可以从Python协议缓冲区对象生成JSON。例如,以下代码生成一个字符串,其中包含的JSON表示形式
GraphDef:
import tensorflow as tffrom google.protobuf import json_formatwith tf.Graph().as_default() as graph: # Add nodes to the graph...graph_def = graph.as_graph_def()json_string = json_format.MessageToJson(graph_def)



