经过摸索,简单使用summary,尤其注意下面代码加粗变量,加粗的是二进制变量,需要写入文件的;
以及运行的软件要有/tmp/XIAO文件夹的权限
# /usr/bin/python3
import tensorflow as tfsess = tf.Session()with tf.name_scope("XiaoGongWei"):a = tf.placeholder(dtype=tf.float32)b = tf.Variable([1.0],dtype=tf.float32)W = tf.Variable([1,2],dtype=tf.float32)addAB = W * a + btf.summary.scalar("wight_max",tf.reduce_mean(W))tf.summary.scalar("b_value",tf.reduce_mean(b))tf.summary.scalar("a_value",tf.reduce_mean(a))merged = tf.summary.merge_all()train_summary = tf.summary.FileWriter('/tmp/XIAO/',sess.graph)sess.run(tf.global_variables_initializer())for i in range(100):tfmensumm,myadd = sess.run([merged,addAB],feed_dict={a:i})print(myadd)train_summary.add_summary(tfmensumm,i)train_summary.close()
运行代码1次后会在对应/tmp/XIAO出现一个文件
然后终端运行 tensorboard --logdir=/tmp/XIAO
打开浏览器输入:0.0.0.0:6006就会出现scalar保存结果
本文作为初学的测试,谢谢大家评论