2016-08-26 53 views
0

我遇到了代碼順序影響最終結果的問題。起初,代碼起作用。在移動一條線後,張量流產生一個錯誤。代碼順序影響最終結果

例如,

工作版本:

probs = net.get_output() 
label_node = tf.placeholder(tf.int32, name='label_node') 
top_1_op = tf.nn.in_top_k(probs, label_node, 1) 
top_5_op = tf.nn.in_top_k(probs, label_node, 5) 
threads = image_producer.start(session=sess, coordinator=coordinator) 
for (labels, images) in image_producer.batches(sess): 
    top_1_result, top_5_result = sess.run([top_1_op, top_5_op], 
            feed_dict={input_node: images, label_node: labels}) 

非工作版本:

threads = image_producer.start(session=sess, coordinator=coordinator) # move here 
probs = net.get_output() 
label_node = tf.placeholder(tf.int32, name='label_node') 
top_1_op = tf.nn.in_top_k(probs, label_node, 1) 
top_5_op = tf.nn.in_top_k(probs, label_node, 5) 
for (labels, images) in image_producer.batches(sess): 
    top_1_result, top_5_result = sess.run([top_1_op, top_5_op], 
            feed_dict={input_node: images, label_node: labels}) 

Tensorflow生成錯誤

"tensorflow.python.framework.errors.NotFoundError: FeedInputs: unable to find feed output label_node:0". 

正如您所看到的,tensorflow應該能夠找到「label_node:0」。實際上,tensorflow也找不到top_1_optop_5_op

image_producer.start的內容類似於:

op_A = ... 
queue_runner = tf.train.QueueRunner(queue_B, [op_B] * num_concurrent) 
session.run(op_A) 
t = queue_runner.create_threads(session, coord=coordinator, start=True) 

一個更奇怪的是,在無法使用的版本,之後我在image_producer.start添加兩行,代碼再次工作。例如,image_producer.start變爲

op_C = ... # new 
session.run(op_C) # new 
op_A = ... 
queue_runner = tf.train.QueueRunner(queue_B, [op_B] * num_concurrent) 
session.run(op_A) 
t = queue_runner.create_threads(session, coord=coordinator, start=True) 

有沒有人有關於此問題的可能原因的想法?或者有關如何調試的任何想法?

+0

您正在運行哪個版本的TensorFlow? – mrry

+0

我使用預先安裝在集羣中的張量流。我怎樣才能知道這個版本? – denru

+0

最簡單的方法是運行命令'python -c'import tensorflow as tf; print tf .__ version __''。 – mrry

回答

1

聽起來好像你患了bug,這是在TensorFlow 0.9.0發佈後修復的。在該版本(及更早版本)中,TensorFlow遇到競態條件,如果您在隊列運行程序(或其他調用sess.run()的線程)啓動後修改了圖形,則會導致不可恢復的錯誤。 0.9.0版本中的唯一解決方法是啓動 隊列運行程序(即代碼中的image_producer之後圖形已完全構建。

+0

謝謝。我會試着要求管理員將其升級到0.10,然後檢查這個問題是否解決。 – denru