イメージがあるディレクトリーと、ラベル・ファイルを持つ別のディレクトリー(各イメージ用)があります。私はイメージとラベルをキューと読み取り操作を使用して読み取ろうとしています。新しいキューランナーを追加するとプログラムが早期に終了する
image_file_queue = tf.train.string_input_producer(image_files, num_epochs=1, shuffle=False)
image_reader = tf.WholeFileReader()
image_contents = image_reader.read(image_file_queue)[1]
image = tf.image.decode_jpeg(image_contents, channels=3)
image = tf.image.resize_images(image, [image_size, image_size])
image_batch = tf.train.batch([image],
batch_size,
num_threads=4,
capacity=2 * batch_size,
allow_smaller_final_batch=True)
label_file_queue = tf.train.string_input_producer(label_files, num_epochs=1, shuffle=False)
label_reader = tf.WholeFileReader()
label_contents = tf.string_split([label_reader.read(label_file_queue)[1]], delimiter='\n').values
labels = tf.decode_csv(label_contents, [tf.constant([], dtype=tf.float32)] * 5, field_delim=' ')
label_queue = tf.FIFOQueue(2 * batch_size, [tf.float32])
enqueue_op = label_queue.enqueue([labels])
label_queue_runner = tf.train.QueueRunner(label_queue, enqueue_ops=[enqueue_op] * 2)
tf.train.add_queue_runner(label_queue_runner)
coord = tf.train.Coordinator()
sess.run(tf.group(tf.local_variables_initializer(), tf.global_variables_initializer()))
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
ただし、これは機能しません。 coord.should_stop()
はこの直後にTrue
を返します。コメントtf.train.add_queue_runner(...)
が動作します。つまり、image_batch
が計算され、CNNで実行できます。私がコメントしなければ、image_batch
はそれより小さいと思われます(batch_size
は128ですが、image_batch.eval().shape
は8にすることができます)。これは不十分なスレッドのためかもしれないと思ったが、inter_op_parallelism_threads
とintra_op_parallelism_threads
の両方を増やしてもこの問題は修正されない。
'image_batch.eval()。shape 'の部分は、' allow_smaller_final_batch = True'のため8である可能性がありますか? – jkschin
いいえ、読めるほどの画像があります。それは常に8ではありません、それは変化し続けます。 – Priyatham