TensorFlow可視化工具TensorBoard默認圖與自定義圖
一、圖
圖:數(shù)據(jù)(張量Tenrsor)+ 操作(節(jié)點Operation) (靜態(tài))
圖可以用:1、默認圖;2、自定義圖。
1、默認圖
查看默認圖的方式:
- 1、調(diào)用方法:tf.get_default_graph()
- 2、查看屬性:.graph
1、調(diào)用方法查看默認圖屬性
# 方法一:調(diào)用方法
default = tf.get_default_graph()
print('default:', default)
![]()
2、.graph查看圖屬性
# 方法二:查看屬性
# 查看節(jié)點屬性
print('a的屬性:', a.graph)
print('c的屬性:', c.graph)
# 查看會話屬性
print('會話sess的圖屬性:', sess.graph)


可以發(fā)現(xiàn)這些圖的地址都是同一個地址,是因為它們都是默認使用了默認圖。
代碼
# 查看默認圖
def View_Graph():
# 方法一:調(diào)用方法
default = tf.get_default_graph()
print('default:', default)
# 方法二:查看屬性
# 查看節(jié)點屬性
print('a的屬性:', a.graph)
print('c的屬性:', c.graph)
# 查看會話屬性
print('會話sess的圖屬性:', sess.graph)
2、自定義圖(創(chuàng)建圖)
1、創(chuàng)建自定義圖
# 1 創(chuàng)建自定義圖
new_graph = tf.Graph()
print(new_graph)
![]()
2、創(chuàng)建靜態(tài)圖
# 2 創(chuàng)建靜態(tài)圖(張量和節(jié)點)
with new_graph.as_default():
a = tf.constant(10)
b = tf.constant(20)
c = a + b
print(c)
3、開啟會話(運行)
# 3 開啟對話(運行)
with tf.Session(graph=new_graph) as sess:
print('c=', sess.run(c))
![]()
4、查看自定義圖
# 4 查看自定義圖
View_Graph(a, b, c, sess)
# 查看圖
def View_Graph(a, b, c, sess):
# 方法一:調(diào)用方法
default = tf.get_default_graph()
print('default:', default)
# 方法二:查看屬性
# 查看節(jié)點屬性
print('a的屬性:', a.graph)
print('c的屬性:', c.graph)
# 查看會話屬性
print('會話sess的圖屬性:', sess.graph)

代碼
# 自定義圖
def Create_myGraph():
# 1 創(chuàng)建自定義圖
new_graph = tf.Graph()
print(new_graph)
# 2 創(chuàng)建靜態(tài)圖(張量和節(jié)點)
with new_graph.as_default():
a = tf.constant(10)
b = tf.constant(20)
c = a + b
print(c)
# 3 開啟對話(運行)
with tf.Session(graph=new_graph) as sess:
print('c=', sess.run(c))
# 4 查看自定義圖
View_Graph(a, b, c, sess)
二、TensorBoard可視化
1、可視化處理
tf.summary.FileWriter(path, graph=)
# 可視化
tf.summary.FileWriter("C:\\Users\\Administrator\\Desktop\\summary", graph=sess.graph) #path 圖
2、 打開TensorBoard
在cmd中操作:
1、先移到文件夾的前面
cd C://Users//Administrator//Desktop
2、 打開TensorBoard(從文件中獲取數(shù)據(jù))
tensorboard --logdir=summary

3、打開給定的網(wǎng)址
http://localhost:6006/(cmd中給的網(wǎng)址)
得到可視化結(jié)果:

總代碼
import tensorflow as tf
# 創(chuàng)建TensorFlow框架
def Create_Tensorflow():
# 圖(靜態(tài))
a = tf.constant(2) # 數(shù)據(jù)1(張量)
b = tf.constant(6) # 數(shù)據(jù)2(張量)
c = a + b # 操作(節(jié)點)
# 會話(執(zhí)行)
with tf.Session() as sess:
print('c=', sess.run(c))
# 可視化
tf.summary.FileWriter("C:\\Users\\Administrator\\Desktop\\summary", graph=sess.graph)
# 查看默認圖
View_Graph(a, b, c, sess)
# 查看圖
def View_Graph(a, b, c, sess):
# 方法一:調(diào)用方法
default = tf.get_default_graph()
print('default:', default)
# 方法二:查看屬性
# 查看節(jié)點屬性
print('a的屬性:', a.graph)
print('c的屬性:', c.graph)
# 查看會話屬性
print('會話sess的圖屬性:', sess.graph)
# 自定義圖
def Create_myGraph():
# 1 創(chuàng)建自定義圖
new_graph = tf.Graph()
print(new_graph)
# 2 創(chuàng)建靜態(tài)圖(張量和節(jié)點)
with new_graph.as_default():
a = tf.constant(10)
b = tf.constant(20)
c = a + b
print(c)
# 3 開啟對話(運行)
with tf.Session(graph=new_graph) as sess:
print('c=', sess.run(c))
# 4 查看自定義圖
View_Graph(a, b, c, sess)
if __name__ == '__main__':
# 創(chuàng)建TensorFlow框架
Create_Tensorflow()
# 創(chuàng)建自定義圖
Create_myGraph()
以上就是TensorFlow可視化工具TensorBoard默認圖與自定義圖 的詳細內(nèi)容,更多關于TensorFlow可視化TensorBoard工具的資料請關注腳本之家其它相關文章!
相關文章
Python?的矩陣傳播機制Broadcasting和矩陣運算
這篇文章主要介紹了Python?的矩陣傳播機制Broadcasting和矩陣運算,文章圍繞主題展開詳細的內(nèi)容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-06-06
python+opencv+selenium自動化登錄郵箱并解決滑動驗證的問題
本文主要講解基于python+opencv+selenium自動化登錄郵箱并解決滑動驗證的問題,在這大家需要注意頁面元素定位及文本框和驗證碼的frame嵌套問題,感興趣的朋友一起看看吧2021-07-07
基于文件路徑中/?\?//?\\的用法以及絕對相對路徑的問題
這篇文章主要介紹了基于文件路徑中/?\?//?\\的用法以及絕對相對路徑的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-02-02
淺談Python中threading join和setDaemon用法及區(qū)別說明
這篇文章主要介紹了淺談Python中threading join和setDaemon用法及區(qū)別說明,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-05-05

