TensorBoard 计算图的可视化实现


Posted in Python onFebruary 15, 2020

简介

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/.

效果截图

TensorBoard 计算图的可视化实现

图3-1 logdir中的文件

TensorBoard 计算图的可视化实现

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

TensorBoard 计算图的可视化实现

figure 3-3 计算图的可视化

给出一些建议:

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

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

以上这篇TensorBoard 计算图的可视化实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python 列表(List)操作方法详解
Mar 11 Python
Python深入06——python的内存管理详解
Dec 07 Python
python itchat实现微信自动回复的示例代码
Aug 14 Python
Django中login_required装饰器的深入介绍
Nov 24 Python
windows下安装python的C扩展编译环境(解决Unable to find vcvarsall.bat)
Feb 21 Python
python使用beautifulsoup4爬取酷狗音乐代码实例
Dec 04 Python
python内置模块collections知识点总结
Dec 19 Python
opencv 实现特定颜色线条提取与定位操作
Jun 02 Python
浅谈keras中loss与val_loss的关系
Jun 22 Python
python中实现栈的三种方法
Dec 19 Python
Matlab使用Plot函数实现数据动态显示方法总结
Feb 25 Python
如何用Python搭建gRPC服务
Jun 30 Python
TensorBoard 计算图的查看方式
Feb 15 #Python
pycharm 更改创建文件默认路径的操作
Feb 15 #Python
PyCharm刷新项目(文件)目录的实现
Feb 14 #Python
浅谈Pycharm最有必要改的几个默认设置项
Feb 14 #Python
python图形开发GUI库pyqt5的详细使用方法及各控件的属性与方法
Feb 14 #Python
python图形开发GUI库pyqt5的基本使用方法详解
Feb 14 #Python
Python 写了个新型冠状病毒疫情传播模拟程序
Feb 14 #Python
You might like
destoon找回管理员密码的方法
2014/06/21 PHP
windows7下安装php的php-ssh2扩展教程
2014/07/04 PHP
PHP执行linux命令常用函数汇总
2016/02/02 PHP
PHP抽象类和接口用法实例详解
2019/07/20 PHP
在laravel框架中使用model层的方法
2019/10/08 PHP
基于jquery的tab切换 js原理
2010/04/01 Javascript
js 绑定带参数的事件以及手动触发事件
2010/04/27 Javascript
javascript学习笔记(九) js对象 设计模式
2012/06/19 Javascript
JS获取地址栏参数的小例子
2013/08/23 Javascript
浅谈JavaScript字符集
2014/05/22 Javascript
jQuery+AJAX实现网页无刷新上传
2015/02/22 Javascript
JavaScript控制按钮可用或不可用的方法
2015/04/03 Javascript
jquery siblings获取同辈元素用法实例分析
2016/07/25 Javascript
js无法获取到html标签的属性的解决方法
2016/07/26 Javascript
js获取时间函数及扩展函数的方法
2016/10/30 Javascript
微信小程序 地图(map)实例详解
2016/11/16 Javascript
jQuery File Upload文件上传插件使用详解
2016/12/06 Javascript
Kindeditor单独调用多图上传实例
2017/07/31 Javascript
node跨域请求方法小结
2017/08/25 Javascript
详解BootStrap表单验证中重置BootStrap-select验证提示不清除的坑
2019/09/17 Javascript
VUE table表格动态添加一列数据,新增的这些数据不可以编辑(v-model绑定的数据不能实时更新)
2020/04/03 Javascript
Python之eval()函数危险性浅析
2014/07/03 Python
Python 多核并行计算的示例代码
2017/11/07 Python
PyQt5实现五子棋游戏(人机对弈)
2020/03/24 Python
Python依赖包整体迁移方法详解
2019/08/15 Python
DataReader和DataSet的异同
2014/12/31 面试题
介绍一下常见的木马种类
2014/11/15 面试题
大学毕业生通用自我评价
2014/01/05 职场文书
中学家长会邀请函
2014/01/17 职场文书
责任胜于能力演讲稿
2014/05/20 职场文书
2015重阳节座谈会主持词
2015/07/30 职场文书
应收账款管理制度
2015/08/06 职场文书
Innodb存储引擎中的后台线程详解
2022/04/03 MySQL
python中pycryto实现数据加密
2022/04/29 Python
Android studio 简单计算器的编写
2022/05/20 Java/Android
详解apache编译安装httpd-2.4.54及三种风格的init程序特点和区别
2022/07/15 Servers