TensorBoard 简介
官网上给的定义是:The computations you'll use tensorflow for (like training a massive deep neural network ) can be complex and confusing . To make it easier to understand, debug, and optimize tensorflow programs,we're included a suite of visualization tools called tensorboard.
也就是说,使用tensorflow这个框架搭建的深度神经网络会很复杂,出错了也很难调试,为了便于用户理解你所训练的网络,也便于调试程序,他们推出了tensorboard这个工具。
那么它到底能干什么呢?You can use tensorboard to visualize your tensorflow graph, plot quantitative metrics about the execution of your graph, and show additional data like images that pass through it.
它可以可视化你的图结构,显示类似准确图,代价值等等指标值,显示参数随着迭代次数的变化,以及它的分布图,显示你训练使用的数据,可以显示很多理解和调试你的网络所需要的东西。要显示什么也是可以在代码中进行控制的,可以这样理解,tensorboard并不是只要你训练了一个网络就会自动生成对应的board,它需要你在代码中加入相应的组件才可以显示到tensorboard中。
tensorboard是依赖tensorflow的,官网说:tensorboard operates by reading tensorflow events files ,which contain summary data that you can generate when running tensorflow . tensorboard的运行通过读取tensorflow的事件文件,文件中包含了所有的tensorflow中生成的总数据。tensorflow在运行的时候会产生很多很多的数据,它也提供了函数去获取这些数据并且保存下来,写到events file中,然后tensorboard读取这些文件,形成可视化的图表展示。
比如说,你要训练一个CNN网络识别MNIST数字,你想要记录学习因子随着迭代次数的改变,你可以对节点执行tf.summary.scalar 操作,然后给每个一summary一个标识名称,也就是 为summary添加一个tag .
当然不止会用到一个summary,如果知道cost的变化,或者参数w和b的变化情况,也可以分别给这些节点添加summary,定义完所有的summary节点后,需要把他们都结合成一个节点 。
use tf.summary.merge_all to combine them into a singel op that generates all the summary data.
在运行summary整合后,会得到一个summary protobuf,将这个哥protobuf通过tf.summary.FileWriter 写入硬盘保存下来。(protobuf全称是protocal buffer,是谷歌开发的一种数据交换的格式)
if you want you could run the merged summary op every sigle steep ,and record a ton of training data . that 's likely to be more data than you need, a better way is to run the op every n steops
在程序运行的时候,可以选择每迭代一次就执行一次合并过的summary op,然后写入磁盘,这样就会有非常多的数据,超过你正常需要的数据,所以可以选择每几个迭代进行一次op。
在cmd中启动tensorboard: tensorboard --logdir = 'path to the log directory