参考文章:https://www.cnblogs.com/fydeblog/p/7429344.html
本代码在【Tensorflow】调用已经保存好的模型继续训练(最简版)基础上添加Tensorboard必要的代码
1.显示网络结构图
import tensorflow as tf
from pathlib import Path
def save(path='./model/transfer_learn'):
saver = tf.train.Saver()
saver.save(sess, path, write_meta_graph=False)
def restore(path='./model/transfer_learn'):
saver = tf.train.Saver()
saver.restore(sess, path)
def train(input):
a = tf.assign_add(input, tf.ones(1))
return a
if __name__ == "__main__":
a = tf.Variable(tf.zeros(1),name='a')
model_file = Path('./model')
with tf.Session() as sess:
writer = tf.summary.FileWriter("logs/", sess.graph)
if model_file.exists():
restore()
else:
sess.run(tf.initialize_all_variables())
for i in range(5):
output = train(a)
print(sess.run(output))
save()
在Session
内添加writer = tf.summary.FileWriter("logs/", sess.graph)
,会生成logs
文件夹.
打开终端,不需要进到logs
内,输入tensorboard --logdir logs
,然后打开生成的链接即可.