TensorBoard 計算圖的可視化實現(xiàn)
簡介
tensorflow 配套的可視化工具, 將你的計算圖畫出來.
當(dāng)訓(xùn)練一個巨大的網(wǎng)絡(luò)的時候, 計算圖既復(fù)雜又令人困惑. TensorBoard 提供了一系列的組件, 可以看到 learning rate 的變化, 看到 objective function 的變化.
tfboard 讀取 tf 運行時你記下的 events files, 來進行可視化. 這些 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
作圖, 對于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會內(nèi)部作正規(guī)化處理, 轉(zhuǎn)換到[0,255](解析 tf_events 即可驗證), float通常對應(yīng)于 softm 之后的概率, 值域為[0,1].
tensor為uint8, 保持不變, tf 不作任何內(nèi)部轉(zhuǎn)換.
attention 可視化, attention 的權(quán)重會作 soft-max 處理, 通常img顯示的效果是, 一行看下來有深有淺, 顏色越白weight越大. 但有時后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 計算圖的可視化
給出一些建議:
網(wǎng)絡(luò)也是分模塊,有結(jié)構(gòu)的, 合理使用 scope 可以讓計算圖清晰優(yōu)雅.
有些tensor來自dataset, 有些來自api中op操作的輸出, 本身沒有明確的名字, 此時用x=tf.identity(x,'name') 給tensor起名字, 便于計算圖中定位. 圖3-3 中的 memory 就是 encoder 的輸出的tensor.
以上這篇TensorBoard 計算圖的可視化實現(xiàn)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
python中實現(xiàn)字符串翻轉(zhuǎn)的方法
這篇文章主要介紹了python中實現(xiàn)字符串翻轉(zhuǎn)的方法,代碼很簡單,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-07-07

