国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

錯誤Tensor is not an element of this graph tensorflow

2019-11-08 18:39:56
字體:
來源:轉載
供稿:網友

1、說明:tensorflow使用圖來定義計算,在session中來執行圖中定義的計算,如果沒有顯式的說明,那么session就跟默認的圖相關聯.graph 和 session應該是一一對應的.下面,舉例說明,session如果和graph不一一對應的話,會出現error

[python] view plain copy 在CODE上查看代碼片import tensorflow as tf    def activation(e, f, g):      return e + f + g    with tf.Graph().as_default():    a = tf.constant([5, 4, 5], name='a')    b = tf.constant([0, 1, 2], name='b')    c = tf.constant([5, 0, 5], name='c')      res = activation(a, b, c)    init = tf.initialize_all_variables()    with tf.Session() as sess:    # Start running Operations on the Graph.    sess.run(init)    hi = sess.run(res)    import tensorflow as tf    def activation(e, f, g):      return e + f + g    with tf.Graph().as_default():    a = tf.constant([5, 4, 5], name='a')    b = tf.constant([0, 1, 2], name='b')    c = tf.constant([5, 0, 5], name='c')      res = activation(a, b, c)  說明:此段代碼描述的是,新增一張圖,然后在該圖上去定義操作,也就是目前我們有兩張圖,一張是系統自定義的圖.[python]%20view%20plain%20copy%20init = tf.initialize_all_variables()    with tf.Session() as sess:    # Start running operations on the Graph.    sess.run(init)    hi = sess.run(res)    print hi  說明:此段代碼,其實是描述的是,在默認的圖上去定義了初始化操作,然后想在默認圖上去執行res操作,注意res操作是在我們自定義的圖上的。所以,當然是會報錯的.

修改一:

[python]%20view%20plain%20copy%20import tensorflow as tf    def activation(e, f, g):      return e + f + g    with tf.Graph().as_default():    a = tf.constant([5, 4, 5], name='a')    b = tf.constant([0, 1, 2], name='b')    c = tf.constant([5, 0, 5], name='c')      res = activation(a, b, c)    init = tf.initialize_all_variables()    with tf.Session() as sess:    # Start running operations on the Graph.    sess.run(init)    #hi = sess.run(res)    #print hi  說明:這樣修改就沒問題,只在session上運行init操作,也就是在默認圖上執行session操作.

修改二:

[python]%20view%20plain%20copy%20派生到我的代碼片import tensorflow as tf    def activation(e, f, g):      return e + f + g    with tf.Graph().as_default():    a = tf.constant([5, 4, 5], name='a')    b = tf.constant([0, 1, 2], name='b')    c = tf.constant([5, 0, 5], name='c')      res = activation(a, b, c)      init = tf.initialize_all_variables()      with tf.Session() as sess:      # Start running operations on the Graph.      sess.run(init)      hi = sess.run(res)      print hi  說明:把所有的操作都定義在我們指定的圖上面,并且,session也定義在縮進內,相當于該session只和我們定義的圖相關聯,只執行我們定義在圖內的操作,這樣就不會報錯.
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 腾冲县| 汾西县| 清镇市| 大冶市| 汾阳市| 金寨县| 革吉县| 长治市| 济阳县| 华容县| 康定县| 井研县| 洞口县| 将乐县| 图片| 长沙县| 盱眙县| 三亚市| 古交市| 佛坪县| 乌海市| 宁阳县| 建瓯市| 乳山市| 利辛县| 宁陵县| 临澧县| 福鼎市| 长丰县| 南平市| 镇巴县| 淮滨县| 达尔| 天峨县| 江西省| 罗甸县| 社会| 抚松县| 延津县| 隆回县| 抚松县|