人妖在线一区,国产日韩欧美一区二区综合在线,国产啪精品视频网站免费,欧美内射深插日本少妇

新聞動態(tài)

TensorFlow可視化工具TensorBoard默認圖與自定義圖

發(fā)布日期:2021-12-24 16:04 | 文章來源:腳本之家

一、圖

圖:數(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)址)

得到可視化結果:

總代碼

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工具的資料請關注本站其它相關文章!

版權聲明:本站文章來源標注為YINGSOO的內(nèi)容版權均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務器上建立鏡像,否則將依法追究法律責任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內(nèi)容涉嫌侵權,請聯(lián)系alex-e#qq.com處理。

相關文章

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務

7x24全年不間斷在線

專屬顧問服務

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務熱線

關注
微信

關注官方微信
頂部