mac下查看tensorboard中的graph

這裏簡單介紹下在tensorflow中查看計算圖的方法:

首先是一個簡單的例子:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Aug  9 09:32:50 2018

@author: lilong
"""

import tensorflow as tf
# 定義一個graph類
graph = tf.Graph()

# 定義圖
with graph.as_default():
    # 定義了foo與bar的兩個變量,最後對這個值求和
    foo = tf.Variable(3,name='foo')
    bar = tf.Variable(2,name='bar')
    result = foo + bar
    # 初始化所有變量
    initialize = tf.global_variables_initializer()
#print(result)  #Tensor("add:0", shape=(), dtype=int32)

# 定義一個session,進行真正的計算
with tf.Session(graph=graph) as sess:
    # 執行初始化
    sess.run(initialize)
    res = sess.run(result)

summary_writer = tf.summary.FileWriter("log", sess.graph)
summary_writer.close()

這個時候打開終端,輸入的命令依次如下:

  • 打開tensorflow的運行環境:source activate tensorflow
  • 進入log的目錄文件夾:cd desktop/tensorflow/
  • 輸入tensorboard命令:tensorboard –logdir=”log”
  • 在瀏覽器中輸入網址:http:localhost:6006

如下圖所示:
這裏寫圖片描述

這裏要注意在瀏覽器中輸入的網址並不是終端中的:http://adminodeMacBook-Pro-3.local:6006
而是要輸入:http:localhost:6006

顯示如下:
這裏寫圖片描述

感覺圖計算還是蠻有意思的。。。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章