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


可以發(fā)現(xiàn)這些圖的地址都是同一個(gè)地址,是因?yàn)樗鼈兌际悄J(rèn)使用了默認(rèn)圖。
代碼
# 查看默認(rèn)圖
def View_Graph():
# 方法一:調(diào)用方法
default = tf.get_default_graph()
print('default:', default)
# 方法二:查看屬性
# 查看節(jié)點(diǎn)屬性
print('a的屬性:', a.graph)
print('c的屬性:', c.graph)
# 查看會(huì)話屬性
print('會(huì)話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é)點(diǎn))
with new_graph.as_default():
a = tf.constant(10)
b = tf.constant(20)
c = a + b
print(c)
3、開啟會(huì)話(運(yùn)行)
# 3 開啟對(duì)話(運(yùn)行)
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é)點(diǎn)屬性
print('a的屬性:', a.graph)
print('c的屬性:', c.graph)
# 查看會(huì)話屬性
print('會(huì)話sess的圖屬性:', sess.graph)

代碼
# 自定義圖
def Create_myGraph():
# 1 創(chuàng)建自定義圖
new_graph = tf.Graph()
print(new_graph)
# 2 創(chuàng)建靜態(tài)圖(張量和節(jié)點(diǎn))
with new_graph.as_default():
a = tf.constant(10)
b = tf.constant(20)
c = a + b
print(c)
# 3 開啟對(duì)話(運(yùn)行)
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é)點(diǎn))
# 會(huì)話(執(zhí)行)
with tf.Session() as sess:
print('c=', sess.run(c))
# 可視化
tf.summary.FileWriter("C:\\Users\\Administrator\\Desktop\\summary", graph=sess.graph)
# 查看默認(rèn)圖
View_Graph(a, b, c, sess)
# 查看圖
def View_Graph(a, b, c, sess):
# 方法一:調(diào)用方法
default = tf.get_default_graph()
print('default:', default)
# 方法二:查看屬性
# 查看節(jié)點(diǎn)屬性
print('a的屬性:', a.graph)
print('c的屬性:', c.graph)
# 查看會(huì)話屬性
print('會(huì)話sess的圖屬性:', sess.graph)
# 自定義圖
def Create_myGraph():
# 1 創(chuàng)建自定義圖
new_graph = tf.Graph()
print(new_graph)
# 2 創(chuàng)建靜態(tài)圖(張量和節(jié)點(diǎn))
with new_graph.as_default():
a = tf.constant(10)
b = tf.constant(20)
c = a + b
print(c)
# 3 開啟對(duì)話(運(yùn)行)
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默認(rèn)圖與自定義圖 的詳細(xì)內(nèi)容,更多關(guān)于TensorFlow可視化TensorBoard工具的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
Python實(shí)現(xiàn)的簡(jiǎn)單dns查詢功能示例
這篇文章主要介紹了Python實(shí)現(xiàn)的簡(jiǎn)單dns查詢功能,結(jié)合實(shí)例形式分析了Python基于socket模塊的dns信息查詢實(shí)現(xiàn)技巧,需要的朋友可以參考下2017-05-05
Python?的矩陣傳播機(jī)制Broadcasting和矩陣運(yùn)算
這篇文章主要介紹了Python?的矩陣傳播機(jī)制Broadcasting和矩陣運(yùn)算,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-06-06
python+opencv+selenium自動(dòng)化登錄郵箱并解決滑動(dòng)驗(yàn)證的問題
本文主要講解基于python+opencv+selenium自動(dòng)化登錄郵箱并解決滑動(dòng)驗(yàn)證的問題,在這大家需要注意頁面元素定位及文本框和驗(yàn)證碼的frame嵌套問題,感興趣的朋友一起看看吧2021-07-07
基于文件路徑中/?\?//?\\的用法以及絕對(duì)相對(duì)路徑的問題
這篇文章主要介紹了基于文件路徑中/?\?//?\\的用法以及絕對(duì)相對(duì)路徑的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-02-02
Python Process多進(jìn)程實(shí)現(xiàn)過程
這篇文章主要介紹了Python Process多進(jìn)程實(shí)現(xiàn)過程,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-10-10
淺談Python中threading join和setDaemon用法及區(qū)別說明
這篇文章主要介紹了淺談Python中threading join和setDaemon用法及區(qū)別說明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-05-05

