第一阶段-入门详细图文讲解tensorflow1.4 -(九)TensorBoard: Visualizing Learning

这篇教程介绍了TensorBoard的使用,它是TensorFlow的可视化工具,帮助理解、调试和优化TensorFlow程序。通过创建TensorFlow图,添加summary操作来记录学习率、损失等数据,然后使用tf.summary.merge_all合并节点,利用tf.summary.FileWriter将数据写入磁盘。在TensorBoard中可以观察到权重、准确率等训练过程的变化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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’ve included a suite of visualization tools called 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. When TensorBoard is fully configured, it looks like this:

TensorBoard 涉及到的运算在训练大量的深度神经网络中出现的复杂运算。

为了更方便 TensorFlow 程序的理解、调试与优化,我们发布了一套叫做 TensorBoard 的可视化工具。你可以用 TensorBoard 来展现你的 TensorFlow 图像,绘制图像生成的定量指标图以及附加数据。

当 TensorBoard 设置完成后,它应该是这样子的:
这里写图片描述

This tutorial is intended to get you started with simple TensorBoard usage. There are other resources available as well! The TensorBoard’s GitHub has a lot more information on TensorBoard usage, including tips & tricks, and debugging information.
这篇教程倾向于TensorBoard的简单用法。github上有详细的信息,包括使用,提示,调试。

第一步序列化数据

TensorBoard operates by reading TensorFlow events files, which contain summary data that you can generate when running TensorFlow. Here’s the general lifecycle for summary data within TensorBoard.
读取events files 创建TensorBoard。下面讲解一下summary data的生命周期。

First, create the TensorFlow graph that you’d like to collect summary data from, and decide which nodes you would like to annotate with summary operations.
第一步创建tf graph,这个graph由一些summary data 的nodes组成。

For example, suppose you are training a convolutional neural network for recognizing MNIST digits. You’d like to record how the learning rate varies over time, and how the objective function is changing. Collect these by attaching tf.summary.scalar ops to the nodes that output the learning rate and loss respectively. Then, give each scalar_summary a meaningful tag, like ‘learning rate’ or ‘loss function’.
回顾一下MNIST的例子,我们打算记录学习率,和目标函数的变化。应用怎么做?使用tf.summary.scalar操作

Perhaps you’d also like to visualize the distributions of activations coming off a particular layer, or the distribution of gradients or weights. Collect this data by attaching tf.summary.histogram ops to the gradient outputs and to the variable that holds your weights, respectively.
如果你想看到主要层的分布或者权重分布,怎么做?使用tf.summary.histogram操作

For details on all of the summary operations available, check out the docs on summary operations.
更多详情,请看summary文档

Operations in TensorFlow don’t do anything until you run them, or an op that depends on their output. And the summary nodes that we’ve just created are peripheral to your graph: none of the ops you are currently running depend on them. So, to generate summaries, we need to run all of these summary nodes. Managing them by hand would be tedious, so use tf.summary.merge_all to combine them into a single op that generates all the summary data.
我们需要运行所有节点,管理这个节点的运行效率很低。因此我们使用tf.summary.merge_all 合并所有节点成一个单独的操作,一次生成所有的summary data

Then, you can just run the merged summary op, which will generate a serialized Summary protobuf object with all of your summary data at a given step. Finally, to write this summary data to disk, pass the summary protobuf to a tf.summary.FileWriter.
接着,合并成一个操作之后,会生成一个序列化的Summary protobuf对象。为了将这个对象写入磁盘中,我们使用tf.summary.FileWriter

The FileWriter takes a logdir in its constructor - this logdir is quite important, it’s the directory where all of the events will be written out. Also, the FileWriter can optionally take a Graph in its constructor. If it receives a Graph object, then TensorBoard will visualize your graph along with tensor shape information. This will give you a much better sense

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值