0
我有2個隊列,一個用於文件名,一個用於保存這些文件名的內容。 tf.train.string_input_producer
自動添加QR。我添加了一個QR來排隊第二個隊列。但是,這段代碼掛起,任何意見,讓我找出我缺少的是讚賞。爲什麼有2個隊列運行程序的這段代碼掛起
with tf.Session(graph=tf.Graph(), config=tf.ConfigProto(inter_op_parallelism_threads=4,
intra_op_parallelism_threads=2)) as sess:
images, bottlenecks = tf.import_graph_def(graph_def, return_elements=[IMAGE_BATCH, BOTTLENECKS])
file_name_queue = tf.train.string_input_producer(file_names, num_epochs=1, shuffle=False)
image_queue = tf.FIFOQueue(1024,
[tf.float32],
[tf.TensorShape([image_size, image_size, 3])])
reader = tf.WholeFileReader()
_, contents = reader.read(file_name_queue)
image = tf.image.decode_jpeg(contents, channels=3)
image = tf.image.resize_images(image, [image_size, image_size])
enqueue_op = image_queue.enqueue(image)
coord = tf.train.Coordinator()
tf.train.QueueRunner(image_queue, [enqueue_op] * 2)
sess.run(tf.group(tf.local_variables_initializer(), tf.global_variables_initializer()))
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
while not coord.should_stop():
image_batch = image_queue.dequeue_many(batch_size).eval()
print()
bottleneck_batch = bottlenecks.eval(feed_dict={
images: np.stack(image_batch)
})
編輯:經過一些實驗後,我發現第一個QR運行,但不是第二個。
由於第一隊列運行添加到tf.GraphKeys.QUEUE_RUNNERS集合,這是什麼用於檢查啓動哪個隊列亞軍 - https://github.com/tensorflow/tensorflow/blob/1708b92bb923e420d746a56baafc7d4ddcd5e05e/tensorflow/python /training/queue_runner_impl.py#L365 –
另外,你的第二個隊列運行器沒有被任何東西引用,所以它會在Python之前被Python收集垃圾sess.run –
@YaroslavBulatov是否它(第二個QR)沒有被添加到QUEUE_RUNNERS集合中含蓄? – Priyatham