您好,登錄后才能下訂單哦!
這篇文章主要介紹了TensorFlow可視化工具中TensorBoard默認(rèn)圖與自定義圖的示例分析,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
圖:數(shù)據(jù)(張量Tenrsor)+ 操作(節(jié)點Operation) (靜態(tài))
圖可以用:1、默認(rèn)圖;2、自定義圖。
查看默認(rèn)圖的方式:
1、調(diào)用方法:tf.get_default_graph()
2、查看屬性:.graph
# 方法一:調(diào)用方法 default = tf.get_default_graph() print('default:', default)
# 方法二:查看屬性 # 查看節(jié)點屬性 print('a的屬性:', a.graph) print('c的屬性:', c.graph) # 查看會話屬性 print('會話sess的圖屬性:', sess.graph)
可以發(fā)現(xiàn)這些圖的地址都是同一個地址,是因為它們都是默認(rèn)使用了默認(rèn)圖。
# 查看默認(rè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)
# 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)
# 查看圖 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)
tf.summary.FileWriter(path, graph=)
# 可視化 tf.summary.FileWriter("C:\\Users\\Administrator\\Desktop\\summary", graph=sess.graph) #path 圖
在cmd中操作:
cd C://Users//Administrator//Desktop
tensorboard --logdir=summary
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) # 查看默認(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é)點屬性 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()
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“TensorFlow可視化工具中TensorBoard默認(rèn)圖與自定義圖的示例分析”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。