国产探花免费观看_亚洲丰满少妇自慰呻吟_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只和我們定義的圖相關聯,只執行我們定義在圖內的操作,這樣就不會報錯.
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 竹山县| 文昌市| 镶黄旗| 丰县| 缙云县| 西丰县| 通州区| 郓城县| 马公市| 鸡东县| 新野县| 襄城县| 南康市| 汝州市| 蓬溪县| 沙洋县| 灯塔市| 仲巴县| 溆浦县| 香港 | 肥城市| 武清区| 延庆县| 延吉市| 绥芬河市| 静宁县| 响水县| 上思县| 大庆市| 信阳市| 洞口县| 龙陵县| 广元市| 阿拉善左旗| 西和县| 荔波县| 乾安县| 藁城市| 义乌市| 朝阳县| 朝阳县|