tensorboard查看計算圖

1,代碼

# -*- coding: utf-8 -*-
"""
Created on Mon Apr 22 21:23:18 2019

@author: Larry
"""

import tensorflow as tf
#構造一個計算圖
#y=W*x+b

#權重
W = tf.Variable(2.0, dtype=tf.float32, name = 'Weight')

#偏置
b = tf.Variable(1.0, dtype=tf.float32, name = 'Bias')

#輸入 使用佔位符
x = tf.placeholder(dtype = tf.float32, name = 'Input')

#定義輸入的命名空間
with tf.name_scope('Output'):
    #輸出
    y = W * x + b

#定義日誌
path = './log'

#常量不用初始化,變量需要初始化
init = tf.global_variables_initializer()

#創建一個session

with tf.Session() as sess:
    sess.run(init)
    writer = tf.summary.FileWriter(path,sess.graph)
    
    #計算方程 X是佔位符,所以計算機中要帶入值
    result = sess.run(y,{x:3.0})
    
    print("y = %s" % result)
    

2,打開終端,因爲我的tensorflow安裝在虛擬環境中,此處要在虛擬環境下進行。

具體輸入:

tensorboard --logdir=E:\pythonworks\ML_test1\ML_me\TanzhouLearning\log --host=127.0.0.1

3,最後出現的截圖

在這裏插入圖片描述

4,然後打開chrome瀏覽器,輸入:

http://127.0.0.1:6006

結果:
在這裏插入圖片描述

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