1

我想從文件名列表中張量流量的隊列。列表已經完成,但似乎字符串輸入生產者返回了一個空隊列。可能還有其他原因,代碼不起作用。以下是代碼:tensorflow string_input_producer給出了空隊列

sess = tf.InteractiveSession() 

def read_my_file_format(filename_queue): 
    reader = tf.WholeFileReader() 
    key, value = reader.read(filename_queue) 
    images = tf.image.decode_jpeg(value, channels=3) 
    return images, key 

def input_pipeline(filenames, batch_size, num_epochs, labels): 
    filename_queue = tf.train.string_input_producer(filenames, num_epochs=num_epochs, shuffle=False) 
    image, key = read_my_file_format(filename_queue) 
    return image, key 

sess.run(tf.global_variables_initializer()) 

coord = tf.train.Coordinator() 
threads = tf.train.start_queue_runners(sess = sess, coord = coord, start=True) 

input_pipeline(trainnames, batch_size, None, labels) 

coord.request_stop() 
coord.join(threads) 

回答

0

如果您可以提供錯誤消息,這將有所幫助。

在同一時間,在這裏對你的代碼的一些言論:呼籲sess.run(tf.global_variables_initializer())如果之前

  • 方法input_pipeline定義關聯到隊列中的TensorFlow運營商,並將其添加到圖形,所以你應該把它如果您希望您的隊列由協調員啓動,您希望隊列成爲圖形的一部分,並在呼叫start_queue_runners之前。
  • 您還沒有要求TensorFlow實際運行您的image, key運營商。

下面是代碼我想嘗試:

sess = tf.InteractiveSession() 

def read_my_file_format(filename_queue): 
    reader = tf.WholeFileReader() 
    key, value = reader.read(filename_queue) 
    images = tf.image.decode_jpeg(value, channels=3) 
    return images, key 

def input_pipeline(filenames, batch_size, num_epochs, labels): 
    filename_queue = tf.train.string_input_producer(filenames, num_epochs=num_epochs, shuffle=False) 
    image, key = read_my_file_format(filename_queue) 
    return image, key 

# Let us define the queue operators and add them to the default graph. 
image, key = input_pipeline(trainnames, batch_size, None, labels) 

sess.run(tf.global_variables_initializer()) 

coord = tf.train.Coordinator() 
threads = tf.train.start_queue_runners(sess = sess, coord = coord, start=True) 

# Let's run the image, key tensors. 
sess.run([image, key]) 

coord.request_stop() 
coord.join(threads) 
+0

你能不能也請告訴我如何與圖形管線結合?我瞭解到,我們不能將張量輸入圖的佔位符,在這種情況下,我應該如何給圖輸入輸入?我有兩個不同的隊列中有一個訓練集和一個測試集,是否可以將它們都輸入到一個圖中?如果我將一個圖定義爲一個函數,每次我調用它時它會創建一個新圖還是返回相同的舊圖? – ALeex

+0

基本上,流水線(例如'filename_queue','image','key',...)是圖形的一部分。如果您不想使用feed_dict手動提供佔位符張量,則可以使用圖像張量將其直接輸入到圖形中。基本上,您只是像使用佔位符一樣使用您的出列操作。 我會推薦閱讀[reading_data部分](https://www.tensorflow.org/programmers_guide/reading_data)並查看示例。 關於您最後的問題,本[部分](https://www.tensorflow.org/programmers_guide/variables)可能會引起您的興趣。 – npf

+0

感謝您的幫助,我在閱讀之前已經閱讀了這個問題,但我仍然不確定閱讀後應該怎麼做。所以我會將filename_queue,image和key添加到圖中。我想運行'sess.run([image,key])'會開始出隊並通過圖表?還是僅僅爲了獲得沒有訓練的圖像張量?爲了製作圖表的管道部分,我沒有發現如何同時提供訓練集和測試集的管道,你知道嗎? – ALeex