2017-03-04 42 views

回答

1

我的建議是確保你的會話知道它在哪個圖上運行。 出頭,你可以嘗試是:

  1. 構建圖形第一,並通過在圖形中的會話。

    myGraph = tf.Graph() 
    with myGraph.as_default(): 
        # build your graph here 
    
    mySession = tf.Session(graph=myGraph) 
    mySession.run(...) 
    
    # Or 
    
    with tf.Session(graph=myGraph) as mySession: 
        mySession.run(...) 
    
  2. 如果你想使用多個with聲明,以嵌套的方式來使用它。

    with tf.Graph().as_default(): 
        # build your graph here 
        with tf.Session() as mySession: 
         mySession.run(...)