TensorBoard:可視化學習

2021-03-02 TensorFlow

def variable_summaries(var):
  """Attach a lot of summaries to a Tensor (for TensorBoard visualization)."""
  with tf.name_scope('summaries'):
    mean = tf.reduce_mean(var)
    tf.summary.scalar('mean', mean)
    with tf.name_scope('stddev'):
      stddev = tf.sqrt(tf.reduce_mean(tf.square(var - mean)))
    tf.summary.scalar('stddev', stddev)
    tf.summary.scalar('max', tf.reduce_max(var))
    tf.summary.scalar('min', tf.reduce_min(var))
    tf.summary.histogram('histogram', var)

def nn_layer(input_tensor, input_dim, output_dim, layer_name, act=tf.nn.relu):
  """Reusable code for making a simple neural net layer.

  It does a matrix multiply, bias add, and then uses relu to nonlinearize.
  It also sets up name scoping so that the resultant graph is easy to read,
  and adds a number of summary ops.
  """
  # Adding a name scope ensures logical grouping of the layers in the graph.
  with tf.name_scope(layer_name):
    # This Variable will hold the state of the weights for the layer
    with tf.name_scope('weights'):
      weights = weight_variable([input_dim, output_dim])
      variable_summaries(weights)
    with tf.name_scope('biases'):
      biases = bias_variable([output_dim])
      variable_summaries(biases)
    with tf.name_scope('Wx_plus_b'):
      preactivate = tf.matmul(input_tensor, weights) + biases
      tf.summary.histogram('pre_activations', preactivate)
    activations = act(preactivate, name='activation')
    tf.summary.histogram('activations', activations)
    return activations

hidden1 = nn_layer(x, 784, 500, 'layer1')

with tf.name_scope('dropout'):
  keep_prob = tf.placeholder(tf.float32)
  tf.summary.scalar('dropout_keep_probability', keep_prob)
  dropped = tf.nn.dropout(hidden1, keep_prob)

# Do not apply softmax activation yet, see below.
y = nn_layer(dropped, 500, 10, 'layer2', act=tf.identity)

with tf.name_scope('cross_entropy'):
  # The raw formulation of cross-entropy,
  #
  # tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(tf.softmax(y)),
  #                               reduction_indices=[1]))
  #
  # can be numerically unstable.
  #
  # So here we use tf.losses.sparse_softmax_cross_entropy on the
  # raw logit outputs of the nn_layer above.
  with tf.name_scope('total'):
    cross_entropy = tf.losses.sparse_softmax_cross_entropy(labels=y_, logits=y)
tf.summary.scalar('cross_entropy', cross_entropy)

with tf.name_scope('train'):
  train_step = tf.train.AdamOptimizer(FLAGS.learning_rate).minimize(
      cross_entropy)

with tf.name_scope('accuracy'):
  with tf.name_scope('correct_prediction'):
    correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
  with tf.name_scope('accuracy'):
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
tf.summary.scalar('accuracy', accuracy)

# Merge all the summaries and write them out to /tmp/mnist_logs (by default)
merged = tf.summary.merge_all()
train_writer = tf.summary.FileWriter(FLAGS.summaries_dir + '/train',
                                      sess.graph)
test_writer = tf.summary.FileWriter(FLAGS.summaries_dir + '/test')
tf.global_variables_initializer().run()

相關焦點

  • 推出 TensorBoard.dev
    TensorBoard http://tensorflow.google.cn/tensorboard追蹤實驗指標https://tensorflow.google.cn/tensorboard/scalars_and_keras可視化模型https://tensorflow.google.cn/tensorboard
  • 【Pytorch 】筆記八:Tensorboard 可視化與 Hook 機制
    Tensorboard 的基本使用Tensorbord 的基本使用包括準確率和損失的可視化,參數數據的分布及參數梯度的可視化等。下面我們一一來學習。但是在正式學習之前,我們得先了解一些基礎知識:3.1 SummaryWriter這個類的功能是提供創建 event file 的高級接口。
  • 具有PyTorch Lightning的TensorBoard
    此外,推斷事物的最佳方法是對其進行觀察(可視化)。因此,數據可視化在使我們的直覺提供更快,更準確的解決方案方面變得極為有用。實際上,數據科學和機器學習日復一日地利用它幾乎所有的機器學習愛好者都可以使用可視化工具。
  • 深度學習VGG16捕魚場景分類-WEB可視化
    今天的主題是利用深度學習keras框架做捕魚場景的識別,然後利用tensoflow的tensorboard可視化。
  • Tensorboard機器學習可視化工具
    在定義網絡模型時,需要可視化的目標變量可以通過tf.summary添加。(1)tf.summary.scalar顯示標量信息,主要用於記錄諸如:準確率、損失和學習率等單個值的變化趨勢。x_input, w_conv1) + b_conv1) h_pool1 = self.max_pool_2x2(h_conv1) tf.summary.image('h_pool1', h_pool1[:,:,:,:1], 6)定義網絡過程中可以通過tf.name_scope()來劃分網絡模塊,使得可視化結果可以分塊展示
  • 「技術綜述」深度學習可視化都有哪些要點?
    作者 | 言有三編輯 | 言有三大家最詬病深度學習的一點就是理論基礎不夠系統,模型就像一個黑盒子,這就更加凸顯了深度學習模型可視化的重要性了。本文以實戰經驗為主,除去數據的可視化部分,我們說以下幾個主要的方向(1)模型結構的可視化(2)卷積參數的可視化(3)激活區域的可視化(4)訓練過程的可視化。
  • CNN 模型的可視化
    大家都了解卷積神經網絡 CNN,但是對於它在每一層提取到的特徵以及訓練的過程可能還是不太明白,所以這篇主要通過模型的可視化來神經網絡在每一層中是如何訓練的。我們知道,神經網絡本身包含了一系列特徵提取器,理想的 feature map 應該是稀疏的以及包含典型的局部信息。
  • PyTorch模型訓練特徵圖可視化(TensorboardX)
    0、前言本文所有代碼解讀均基於PyTorch 1.0,Python3;本文為原創文章,初次完成於2019.03,最後更新於2019.09;最近復現的一篇論文一直都難以work,上了特徵圖可視化後一下子就找到了問題所在,所以今天想梳理一下PyTorch裡面的特徵圖可視化。
  • TensorFlow有Tensorboard,MindSpore框架如何做可視化?
    5 月12 日,機器之心聯合華為昇騰學院開設的線上公開課《輕鬆上手開源框架MindSpore》第 6 課完成,王越講師為大家帶來了主題分享《MindSpore可視化工具使用指南》。Q7:訓練中間層可視化?如果中間層可視化是指的是計算圖的中間層信息,可以使用MindInsight中的計算圖可視組件進行查看。
  • 學習筆記TF003:數據流圖定義、執行、可視化
    級聯運算組可視化更容易,無需關心部件內部具體細節。造成循環依賴(circular dependency)的節點連接不被允許。節點輸出是後繼節點計算必須輸入,節點是後繼節點的依賴節點。輸出不需要其他節點任何輸入,互相獨立。依賴關係具有傳遞性。依賴分為直接依賴和間接依賴。節點輸出作為直接或間接依賴節點的輸入,因都需要等待對方計算完成,形成循環依賴。
  • PyTorch Tips(FLOPs計算/參數量/計算圖可視化/相關性分析)
    畫出計算圖PyTorch 1.4版本內置了tensorboard,支持add_graph ,可以將我們定義的模型的計算圖可視化出來,可以直觀的看到每一層的size,和數據流向,為模型調試和驗證提供了很好的幫助參見文檔: pytorch.org/docs/stable
  • 深度學習的學習率調節實踐
    這是通過在每次迭代時將學習速率乘以一個常數因子來實現的。如果你將損失描繪為學習率的函數,你應該首先看到它在下降,但過一段時間後,學習率會變得很高,這時損失會迅速回升:最佳學習率將略低於轉折點,然後你可以重新初始化你的模型,並使用此良好的學習率對其進行正常訓練。
  • PyTorch v1.1 重大更新,TensorBoard已加入豪華套餐
    近日在 2019 年 Facebook 開發者大會「F8」上,Facebook 公布了 PyTorch 的重大更新 1.1 版本,同時還發布並開源了其它多個開發工具,繼續降低機器學習/深度學習模型開發調試以及深度學習專用硬體設計的門檻。雷鋒網(公眾號:雷鋒網) AI 科技評論把更新主要內容介紹如下。
  • 提高學習力的方法之二:可視化學習
    大家好,我是易圖記的loridic,上篇講了一下提高學習力的方法之一:結構化學習,這篇文章講講提高學習力方法二:可視化學習。1、什麼是可視化學習可視化學習,就是把要學的內容用圖的形式展示出來進行學習。目的是更方便理解記憶和運用所學內容。2、怎麼樣進行可視化學習通過畫圖來代替線性筆記,各種圖如下。
  • Keras 深度學習模型可視化
    深度學習可視化深度學習的過程是一個黑盒子,模型通過大量的權重去學習擬合輸入的數據和學習目標,模型的性能很大程度上取決於模型的輸入的數據;深度學習的擬合效果往往出乎我們的的想像,但是模型如何擬合數據和學習目標之間的關係,我們知之甚少。
  • 百度數據可視化實驗室正式成立,發布深度學習可視化平臺 Visual DL
    企業:百度
  • 圖形可視化教學法讓數學學習生動有趣
    圖形可視化教學法讓數學學習生動有趣     本報訊(記者 陽帆)通過一個軟體,學生在電腦上能直觀感受到函數的變化,把書本上抽象的公式變成了電腦屏幕上直觀的圖形。
  • 深度學習訓練過程可視化(附github源碼)
    其實很多還是無法可解釋,但是通過可視化,具體可以知道深度學習在訓練過程到底學習了哪些特徵?到底對該目標的哪些特徵感興趣?這些我們現在已經有很多渠道可以得知,我先給大家介紹幾個比價好的工具!地址:https://github.com/PaddlePaddle/VisualDL4.結構可視化工具PlotNeuralNet地址:https://github.com/HarisIqbal88/PlotNeuralNet其實還有很多可視化工具,但是今天我要說的是,訓練過程的可視化
  • 最強NLP模型BERT可視化學習
    2018年是自然語言處理(Natural Language Processing, NLP)領域的轉折點,一系列深度學習模型在智能問答及情感分類等NLP任務中均取得了最先進的成果。近期,谷歌提出了BERT模型,在各種任務上表現卓越,有人稱其為「一個解決所有問題的模型」。