2
對於我的TensorFlow培訓管道,我使用的是包含要讀取的圖像文件的tf.FIFOQueue
,並使用tf.train.batch
來獲取一批預處理圖像。這工作正常。tf.train.batch - 從dequeue_many操作中獲取項目
出於調試的目的,我現在正在尋找一種方法來獲取中從dequeue_many
操作獲取的文件名。
下面是我的代碼的相應部分。所以我試圖從filename_queue
中獲取批量操作中出隊的str
或tf.string
對象。如果除了重寫tf.train.batch
之類的操作並且自己執行dequeue_many
操作還有解決方案嗎?
filename_queue = tf.FIFOQueue(100000, [tf.string], shapes=[[]])
# ...
reader = tf.WholeFileReader()
_, image_raw = reader.read(filename_queue)
image = tf.image.decode_jpeg(image_raw, channels=3)
# Image preprocessing
image_preproc = ...
# Read a batch of preprocessing images from queue
image_batch = tf.train.batch([image_preproc], batch_size, num_threads=1)
# How to get the filenames corresponding to the images in 'image_batch'?
謝謝jdehesa爲您解答!使用reader.read()的''key'實際上是我正在尋找的解決方案。這個TF功能的文檔雖然可以改進。我的最終解決方案是獲取整批文件名:https://gist.github.com/tomrunia/700585a0d44dff4606f26b7b50856932 –
@ verified.human是的,文檔,它使用抽象(有些隱祕)的術語'鍵'似乎只是從父類['tf.ReaderBase'](https://www.tensorflow.org/api_docs/python/tf/ReaderBase)繼承而來,這是更通用的,並非特定於文件閱讀。 – jdehesa