tensorflow: tensorboard 探究

来源:互联网 发布:arrayslice php 编辑:程序博客网 时间:2024/06/11 15:25

功能模块

Module Annotation SCALARS 记录单一变量的,使用 tf.summary.scalar() 收集构建。 IMAGES 收集的图片数据,当我们使用的数据为图片时(选用),使用 tf.summary.image() 收集构建。 AUDIO 收集的音频数据,当我们使用数据为音频时(选用)。 GRAPHS 构件图,效果图类似流程图一样,我们可以看到数据的流向,使用tf.name_scope()收集构建。 DISTRIBUTIONS 用于查看变量的分布值,比如 W(Weights)变化的过程中,主要是在 0.5 附近徘徊。 HISTOGRAMS 用于记录变量的历史值(比如 weights 值,平均值等),并使用折线图的方式展现,使用tf.summary.histogram()进行收集构建。


打开方式

法一

  代码运行完成之后,可以用bash脚本一键浏览器访问tensorboard终端:

xdg-open 'http://localhost:6006/#histograms'tensorboard --logdir=.

法二

  代码运行完成之后,命令行中跳转到代码生成的文件夹中,输入

tensorboard --logdir .

  等待程序反应之后,浏览器访问

localhost:6006

  也可以自己定义端口

demo

这里写图片描述



这里写图片描述


这里写图片描述


这里写图片描述

源码

  打开终端,执行 bash run.sh 即可一键生成 tensorboard log 并自动打开 6006端口

main.py:

log_path = './log'N = 400import shutiltry:    shutil.rmtree(log_path)except OSError:    passimport tensorflow as tfk = tf.placeholder(dtype=tf.float32)moving_mean = tf.random_normal(shape=[1000], mean=(5*k), stddev=1)tf.summary.histogram('normal/moving_mean', moving_mean)shrinking_mean = tf.random_normal(shape=[1000], mean=0, stddev=1-k)tf.summary.histogram('normal/shrinking_mean', shrinking_mean)normal_combined = tf.concat([moving_mean, shrinking_mean], axis=0)tf.summary.histogram('normal/normal_combined', normal_combined)gamma = tf.random_gamma(shape=[1000], alpha=k)tf.summary.histogram('other/gamma', gamma)poisson = tf.random_poisson(lam=k, shape=[1000])tf.summary.histogram('other/poisson', poisson)uniform = tf.random_uniform(shape=[1000], minval=k*10)tf.summary.histogram('other/uniform', uniform)all_combined = tf.concat([moving_mean, shrinking_mean, gamma, poisson, uniform], axis=0)tf.summary.histogram('all_combined', all_combined)summaries = tf.summary.merge_all()sess = tf.Session()writer = tf.summary.FileWriter(log_path)for step in range(N):    val = step/float(N)    merge_op = sess.run(summaries, feed_dict={k:val})    writer.add_summary(summary=merge_op, global_step=step)writer.close()

run.sh:

python main.pyxdg-open 'http://localhost:6006/#histograms'tensorboard --logdir=./