tensorflow 1.14 的 demo 02 —— tensorboard 远程访问
tensorflow 1.14.0, 提供远程访问 tensorboard 服务的方法
第一步生成 events 文件:
在上一篇demo的基础上加了一句,如下,
tf.summary.FileWriter("./tmp/summary", graph=sess1.graph)
hello_tensorboard_remote.py
import tensorflow as tf
import os
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'def tf114_demo():a = 3b = 4c = a + bprint("a + b in py =",c)a_t = tf.constant(3)b_t = tf.constant(4)c_t = a_t + b_tprint("TensorFlow add a_t + b_t =", c_t)with tf.Session() as sess:c_t_value = sess.run(c_t)print("c_t_value= ", c_t_value)return Nonedef graph_demo():a_t = tf.constant(3)b_t = tf.constant(4)c_t = a_t + b_tprint("TensorFlow add a_t + b_t =", c_t)default_g = tf.get_default_graph()print("default_g:\n",default_g)print("a_t g:", a_t.graph)print("c_t g:", c_t.graph)with tf.Session() as sess:c_t_value = sess.run(c_t)print("c_t_value= ", c_t_value)print("sess g:", sess.graph)new_g = tf.Graph()with new_g.as_default():a_new = tf.constant(20)b_new = tf.constant(30)c_new = a_new + b_newprint("c_new:", c_new)print("a_new g:",a_new.graph)print("b_new g:",c_new.graph)with tf.Session() as sess1:c_t_value = sess1.run(c_t)
# print("c_new_value:", c_new_value)print("sess1 g:", sess1.graph)tf.summary.FileWriter("./tmp/summary", graph=sess1.graph)with tf.Session(graph=new_g) as new_sess:c_new_value = new_sess.run((c_new))print("c_new_value:", c_new_value)print("new_sess graph properties:", new_sess.graph)
# return Noneif __name__ == "__main__":
# tf114_demo()graph_demo()
运行 tensorflow1 的 app:
python3 hello_tensorboard_remote.py
ls ./tmp/summary/
启动 tensorboard 网络服务:
tensorboard --logdir="./tmp/summary" --port 6789
6789是自己选定的端口号,尝试任选;
运行状态如下:
远程访问tensorboard:
在同一个网络内的主机网页浏览器的地址栏中输入:
http://10.208.14.37:6789
效果如下,显示出来了示例中非常简单的一个计算图:
如果是本机访问,则在地址栏里输入
http://127.0.0.1:6006