欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

TensorBoard 计算图的可视化实现

时间:2021-07-06 10:10:46|栏目:Python代码|点击:

简介

tensorflow 配套的可视化工具, 将你的计算图画出来.

当训练一个巨大的网络的时候, 计算图既复杂又令人困惑. TensorBoard 提供了一系列的组件, 可以看到 learning rate 的变化, 看到 objective function 的变化.

tfboard 读取 tf 运行时你记下的 events files, 来进行可视化. 这些 events files 包含了你记下的 summary data, 它是 protobuffer 格式, 并非文本文件.

推荐使用 Estimator 风格.

类与方法

在 tf.estimator 框架下, 可以直接用 tf.summary.scalar() 这样的方法, 不必显式地创建writer并调用writer.add_summary()

tensorflow.python.summary.writer.writer.FileWriter(SummaryToEventTransformer)

类.

__init__(self, logdir, graph=None,...)

构造函数, Creates a FileWriter and an event file.

tensorflow.python.summary.summary

模块.

scalar(name, tensor, ..) Outputs a Summary protocol buffer containing a single scalar value.

histogram(name, values, collections=None, family=None) Adding a histogram summary makes it possible to visualize your data's distribution in TensorBoard.

image

作图, 对于grap-scale 图来讲, 0表示全黑, 255表示全白.

api, image(name, tensor, max_outputs=3, collections=None, family=None) Outputs a Summary protocol buffer with images. images are built from tensor which must be 4-D with shape [batch_size, height, width, channels] and where channels can be:

1.1-tensor is interpreted as Grayscale.

2.3-tensor is interpreted as RGB.

3.4-tensor is interpreted as RGBA.

tensor为float: 此时, tf会内部作正规化处理, 转换到[0,255](解析 tf_events 即可验证), float通常对应于 softm 之后的概率, 值域为[0,1].

tensor为uint8, 保持不变, tf 不作任何内部转换.

attention 可视化, attention 的权重会作 soft-max 处理, 通常img显示的效果是, 一行看下来有深有浅, 颜色越白weight越大. 但有时后tf内部正规化不符合预期, 出现一行全白的情况, 稳妥起见自己转unit类型.

打开web页面

在命令行中 敲tensorboard --logdir=D:\tf_models\iris, 根据提示打开URL即可.

比如我的为http://yichu-amd:6006/.

效果截图

图3-1 logdir中的文件

图3-2 炫酷的可视化效果

figure 3-3 计算图的可视化

给出一些建议:

网络也是分模块,有结构的, 合理使用 scope 可以让计算图清晰优雅.

有些tensor来自dataset, 有些来自api中op操作的输出, 本身没有明确的名字, 此时用x=tf.identity(x,'name') 给tensor起名字, 便于计算图中定位. 图3-3 中的 memory 就是 encoder 的输出的tensor.

上一篇:Python3爬虫中Ajax的用法

栏    目:Python代码

下一篇:Python学习思维导图(必看篇)

本文标题:TensorBoard 计算图的可视化实现

本文地址:http://www.codeinn.net/misctech/153612.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有