#coding:utf-8
import tensorflow as tf
from tensorflow.python.framework import graph_util
tf.reset_default_graph() # 重置計算圖
output_graph_path = 'model/model_tfnew.pb'
with tf.Session() as sess:
tf.global_variables_initializer().run()
output_graph_def = tf.GraphDef()
# 獲得默認的圖
graph = tf.get_default_graph()
with open(output_graph_path, "rb") as f:
output_graph_def.ParseFromString(f.read())
_ = tf.import_graph_def(output_graph_def, name="")
# 得到當前圖有幾個操作節點
print("%d ops in the final graph." % len(output_graph_def.node))
tensor_name = [tensor.name for tensor in output_graph_def.node]
print(tensor_name)
print('---------------------------')
# 在log_graph文件夾下生產日誌文件,可以在tensorboard中可視化模型
summaryWriter = tf.summary.FileWriter('log_graph/', graph)
for op in graph.get_operations():
# print出tensor的name和值
print(op.name, op.values())