1. 程式人生 > 程式設計 >TensorBoard 計算圖的視覺化實現

TensorBoard 計算圖的視覺化實現

簡介

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,max_outputs=3,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 計算圖的視覺化實現就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援我們。