2017-01-16 180 views

回答

1

據我所知,它是不可能鏈接不同的計算圖創建後,但你有幾個選項。

選項2:創建一個大圖和使用control flow op

output_layer, placeholder = build_my_model() 
something = tf.where(output_layer < 0, do_something_1(), do_something_2()) 

所有函數調用上面應該返回tensorflow操作。

選項2:創建兩個圖表和執行內部蟒蛇

# Build the first graph 
with tf.Graph().as_default() as graph: 
    output_layer, placeholder = build_my_model() 

# Build the second two graphs 
with tf.Graph().as_default() as graph_1: 
    something_1 = do_something_1() 
with tf.Graph().as_default() as graph_2: 
    something_2 = do_something_2() 

條件語句作爲結果,你也將結束與三個不同的會議,你需要從第一屆輸出喂之一另外兩個

# Get the output 
_output_layer = sess.run(output_layer, {placeholder: ...}) 
if _output_layer < 0: 
    something = sess1.run(something_1, {...}) 
else: 
    something = sess2.run(something_2, {...}) 

正如你所看到的,如果你可以擺脫控制流操作,你的代碼將會非常簡單。在一張圖中包含所有內容的另一個優點是整個圖是可區分的,並且您可以根據稍後階段的損失來訓練模型第一階段的參數。

+1

btw,graph_editor可以用來連接東西在一起,即graph_editor.ge.reroute_a2b_ts(new_input,old_input)將「連接」new_input tensor old_input用於去 –

+0

非常酷,感謝指出。 –