欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

TensorFlow命名空間和TensorBoard圖節(jié)點(diǎn)實(shí)例

 更新時(shí)間:2020年01月23日 17:31:04   作者:legend_hua  
今天小編就為大家分享一篇TensorFlow命名空間和TensorBoard圖節(jié)點(diǎn)實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

一,命名空間函數(shù)

tf.variable_scope 
tf.name_scope 
先以下面的代碼說(shuō)明兩者的區(qū)別

 # 命名空間管理函數(shù)
'''
說(shuō)明tf.variable_scope和tf.name_scope的區(qū)別
'''
def manage_namespace():
 with tf.variable_scope("foo"):
  # 在命名空間foo下獲取變量"bar",于是得到的變量名稱(chēng)為"foo/bar"。
  a = tf.get_variable("bar",[1]) #獲取變量名稱(chēng)為“bar”的變量
  print a.name  #輸出:foo/bar:0
 with tf.variable_scope("bar"):
  # 在命名空間bar下獲取變量"bar",于是得到的變量名稱(chēng)為"bar/bar"。
  a = tf.get_variable("bar",[1])
  print a.name  #輸出:bar/bar:0
 with tf.name_scope("a"):
  # 使用tf.Variable函數(shù)生成變量會(huì)受tf.name_scope影響,于是得到的變量名稱(chēng)為"a/Variable"。
  a = tf.Variable([1]) #新建變量
  print a.name  #輸出:a/Variable:0

  # 使用tf.get_variable函數(shù)生成變量不受tf.name_scope影響,于是變量并不在a這個(gè)命名空間中。
  a = tf.get_variable("b",[1])
  print a.name  #輸出:b:0
 with tf.name_scope("b"):
  # 使用tf.get_variable函數(shù)生成變量不受tf.name_scope影響,所以這里將試圖獲取名稱(chēng)
  # 為“b”的變量。然而這個(gè)變量已經(jīng)被聲明了,于是這里會(huì)報(bào)重復(fù)聲明的錯(cuò)誤
  tf.get_variable("b",[1])#提示錯(cuò)誤

二,TensorBoard計(jì)算圖查看

1 以以下代碼實(shí)例,為指定任何的命名空間

def practice_num1():
# 練習(xí)1: 構(gòu)建簡(jiǎn)單的計(jì)算圖
 input1 = tf.constant([1.0, 2.0, 3.0],name="input1")
 input2 = tf.Variable(tf.random_uniform([3]),name="input2")
 output = tf.add_n([input1,input2],name = "add")

#生成一個(gè)寫(xiě)日志的writer,并將當(dāng)前的tensorflow計(jì)算圖寫(xiě)入日志
 writer = tf.summary.FileWriter(ROOT_DIR + "/log",tf.get_default_graph())
 writer.close()

如何使用TensorBoard的過(guò)程不再介紹。查看未指明命名空間的運(yùn)算圖

2 修改代碼制定命名空間之后的代碼

def practice_num1_modify():
 #將輸入定義放入各自的命名空間中,從而使得tensorboard可以根據(jù)命名空間來(lái)整理可視化效果圖上的節(jié)點(diǎn)
 # 練習(xí)1: 構(gòu)建簡(jiǎn)單的計(jì)算圖
 with tf.name_scope("input1"):
  input1 = tf.constant([1.0, 2.0, 3.0],name="input1")
 with tf.name_scope("input2"):
  input2 = tf.Variable(tf.random_uniform([3]),name="input2")
 output = tf.add_n([input1,input2],name = "add")

#生成一個(gè)寫(xiě)日志的writer,并將當(dāng)前的tensorflow計(jì)算圖寫(xiě)入日志
 writer = tf.summary.FileWriter(ROOT_DIR + "/log",tf.get_default_graph())
 writer.close()

查看運(yùn)算圖

上圖只包含命名的兩個(gè)命名空間的節(jié)點(diǎn),我們可以點(diǎn)擊名稱(chēng)“input2”的圖標(biāo)上的+號(hào),展開(kāi)該命名空間

效果:通過(guò)命名空間可以整理可視化效果圖上的節(jié)點(diǎn),使可視化的效果更加清晰。

以上這篇TensorFlow命名空間和TensorBoard圖節(jié)點(diǎn)實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論