远程服务器上使用Tensorboard
1.代码中加入:
python2:
writer = tf.train.SummaryWriter('logs/', sess.graph)
python3:
writer = tf.summary.FileWriter("logs/",sess.graph)
tensorboard会在logs目录下新建许多关于计算图的文件。 举例:
import tensorflow as tf
a = tf.constant([1.0,2.0,3.0],name='input1')
b = tf.Variable(tf.random_uniform([3]),name='input2')
add = tf.add_n([a,b],name='addOP')
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
writer = tf.summary.FileWriter("logs/",sess.graph)
print(sess.run(add))
writer.close()
2.打开终端,登陆远程服务器,加入-L参数,打开tensorboard需要使用的端口:
ssh -L 16006:127.0.0.1:6006 [email protected]
3.训练模型,训练后(或训练时)启动tensorboard:
tensorboard --logdir="logs/"
会随着训练的进行实时更新计算图等文件。
注意,要在相应环境下(可能需要tensorflow环境下) 。先 conda activate py2gpu。
4.打开浏览器,访问url:
http://127.0.0.1:16006/