1. 程式人生 > >tensorboard 之 TF可視化

tensorboard 之 TF可視化

異步 rom ted call director 文本 運行時間 creat 顯示數據

tensorboard是TF提供的一個可視化的工具
1.tensorboard可視化的數據來源?
  將tensorflow程序運行過程中輸出的日誌文件進行可視化展示.
  1.1 tensorflow怎樣輸出日誌文件呢?
    tf.summary.FileWriter
      The FileWriter class provides a mechanism to create an event file in a given directory and add summaries and events to it. The class updates the file contents asynchronously. This allows a trainin
g program to call methods to add data to the file directly from the training loop, without slowing down training.
  FileWriter類使tensorboard支持異步更新程序運行狀態;即tensorflow程序在在訓練過程中,tensorboard可以實時的顯示數據的變化
  tb_ex1.py---簡單的日誌文件的tensorboard可視化程序

技術分享圖片


2.tensorboard可以將哪些數據進行可視化?
  2.1 神經網絡結構(graph)的可視化
    利用命名空間使神經網絡模型的結構更加清晰
      tb_ex2.py---通過命名空間,使計算圖的結構更加簡潔

技術分享圖片

  2.2 TF計算節點的運行時間和內存占用可視化
    2.2.1 tf.RunOptions()#配置運行時需要記錄的信息的protocolmessage
    2.2.2 tf.RunMetadata()#運行時記錄運行信息的protocolmessage
    2.2.3 sess.run(options=run_options, run_metadata=run_metadata)
      run(
        fetches,
        feed_dict=None,
        options=None,
        run_metadata=None
      )
      The optional options argument expects a [RunOptions] proto. The options allow controlling the behavior of this particular step (e.g. turning tracing on).
      The optional run_metadata argument expects a [RunMetadata] proto. When appropriate, the non-Tensor output of this step will be collected there. For example, when users turn on tracing in options,
the profiled info will be collected into this argument and passed back.
      將配置信息和記錄運行信息的protocol buffer傳入 運行的過程,從而記錄運行時每一個節點的時間,空間的開銷信息
    2.2.4 FileWriter.add_run_metadata(run_metadata,)#將節點運行時的信息寫入日誌文件
      add_run_metadata(
        run_metadata,
        tag,
        global_step=None
      )
      Adds a metadata information for a single session.run() call.
      Args:
        run_metadata: A RunMetadata protobuf object.
        tag: The tag name for this metadata.
        global_step: Number. Optional global step counter to record with the StepStats.

    以mnist為例,展示節點的運行時間和內存占用情況
    mnist_inference.py
    mnist_train.py

技術分享圖片


  2.3 變量指標可視化
    2.1和2.2主要是介紹了tensorboard的GRAPHS視圖,來顯示TF的NN結構和graph上的節點信息.TB還有SCALARS,IMAGES,AUDIO,DISTRIBUTIONS,HISTOGRAM和TEXT六個界面來可視化其他監控指標.
    2.3.1 tf.summary.scalar TF中標量(scalar)監控數據隨著訓練(叠代)輪數的變化趨勢
    2.3.2 tf.summary.image TF中使用的圖片數據的顯示.一般用於可視化當前使用的訓練或測試圖片
    2.3.3 tf.summary.histogram TF中tensor取值分布的監控數據隨著訓練(叠代)輪數的變化趨勢
    2.3.4 tf.summary.audio TF中使用的音頻數據
    2.3.5 tf.summary.text TF中使用的文本數據
    tb_mnist_monitor.py---對不同變量指標的監控可視化

技術分享圖片

技術分享圖片

技術分享圖片

技術分享圖片

tensorboard 之 TF可視化