0
2つのキューがあります.1つはファイル名用、もう1つはファイル名の内容保持用です。 tf.train.string_input_producer
は自動的にQRを追加します。私は2番目のキューをエンキューするための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)
})
EDIT:いくつかの実験の後、最初のQRは実行されますが、2番目のQRは実行されませんでした。
最初のキューランナーを開始するためにどのキューランナーをチェックするために使用されるものですtf.GraphKeys.QUEUE_RUNNERSコレクションに追加されているので - https://github.com/tensorflow/tensorflow/blob/1708b92bb923e420d746a56baafc7d4ddcd5e05e/tensorflow/python /training/queue_runner_impl.py#L365 –
また、2番目のキューランナーは何も参照されないため、sess.runの前にPythonによってガベージコレクションが行われます。 –
@YaroslavBulatov QUEUE_RUNNERSコレクションに追加されない(2番目のQR)暗黙のうちに? – Priyatham