TensorBoard 計(jì)算圖的可視化實(shí)現(xiàn)
簡介
tensorflow 配套的可視化工具, 將你的計(jì)算圖畫出來.
當(dāng)訓(xùn)練一個(gè)巨大的網(wǎng)絡(luò)的時(shí)候, 計(jì)算圖既復(fù)雜又令人困惑. TensorBoard 提供了一系列的組件, 可以看到 learning rate 的變化, 看到 objective function 的變化.
tfboard 讀取 tf 運(yùn)行時(shí)你記下的 events files, 來進(jìn)行可視化. 這些 events files 包含了你記下的 summary data, 它是 protobuffer 格式, 并非文本文件.
推薦使用 Estimator 風(fēng)格.
類與方法
在 tf.estimator 框架下, 可以直接用 tf.summary.scalar() 這樣的方法, 不必顯式地創(chuàng)建writer并調(diào)用writer.add_summary()
tensorflow.python.summary.writer.writer.FileWriter(SummaryToEventTransformer)
類.
__init__(self, logdir, graph=None,...)
構(gòu)造函數(shù), 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
作圖, 對(duì)于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: 此時(shí), tf會(huì)內(nèi)部作正規(guī)化處理, 轉(zhuǎn)換到[0,255](解析 tf_events 即可驗(yàn)證), float通常對(duì)應(yīng)于 softm 之后的概率, 值域?yàn)閇0,1].
tensor為uint8, 保持不變, tf 不作任何內(nèi)部轉(zhuǎn)換.
attention 可視化, attention 的權(quán)重會(huì)作 soft-max 處理, 通常img顯示的效果是, 一行看下來有深有淺, 顏色越白weight越大. 但有時(shí)后tf內(nèi)部正規(guī)化不符合預(yù)期, 出現(xiàn)一行全白的情況, 穩(wěn)妥起見自己轉(zhuǎn)unit類型.
打開web頁面
在命令行中 敲tensorboard --logdir=D:\tf_models\iris, 根據(jù)提示打開URL即可.
比如我的為http://yichu-amd:6006/.
效果截圖

圖3-1 logdir中的文件

圖3-2 炫酷的可視化效果

figure 3-3 計(jì)算圖的可視化
給出一些建議:
網(wǎng)絡(luò)也是分模塊,有結(jié)構(gòu)的, 合理使用 scope 可以讓計(jì)算圖清晰優(yōu)雅.
有些tensor來自dataset, 有些來自api中op操作的輸出, 本身沒有明確的名字, 此時(shí)用x=tf.identity(x,'name') 給tensor起名字, 便于計(jì)算圖中定位. 圖3-3 中的 memory 就是 encoder 的輸出的tensor.
以上這篇TensorBoard 計(jì)算圖的可視化實(shí)現(xiàn)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
詳解非極大值抑制算法之Python實(shí)現(xiàn)
非極大值抑制(Non-Maximum Suppression,NMS),顧名思義就是抑制不是極大值的元素,可以理解為局部最大搜索。這個(gè)局部代表的是一個(gè)鄰域,鄰域有兩個(gè)參數(shù)可變,一是鄰域的維數(shù),二是鄰域的大小2021-06-06
python中實(shí)現(xiàn)字符串翻轉(zhuǎn)的方法
這篇文章主要介紹了python中實(shí)現(xiàn)字符串翻轉(zhuǎn)的方法,代碼很簡單,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-07-07
Python中非常實(shí)用的一些功能和函數(shù)分享
這篇文章主要介紹了Python中非常實(shí)用的一些功能和函數(shù)分享,本文講解了帶任意數(shù)量參數(shù)的函數(shù)、使用Glob()查找文件、調(diào)試、生成唯一ID等內(nèi)容,需要的朋友可以參考下2015-02-02
Python基于Socket實(shí)現(xiàn)簡單聊天室
這篇文章主要為大家詳細(xì)介紹了Python基于Socket實(shí)現(xiàn)簡單聊天室,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-02-02

