2017-03-19 17 views
0

イメージがあるディレクトリーと、ラベル・ファイルを持つ別のディレクトリー(各イメージ用)があります。私はイメージとラベルをキューと読み取り操作を使用して読み取ろうとしています。新しいキューランナーを追加するとプログラムが早期に終了する

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_threadsintra_op_parallelism_threadsの両方を増やしてもこの問題は修正されない。

+0

'image_batch.eval()。shape 'の部分は、' allow_smaller_final_batch = True'のため8である可能性がありますか? – jkschin

+0

いいえ、読めるほどの画像があります。それは常に8ではありません、それは変化し続けます。 – Priyatham

答えて

0

jkschinが正しいです。イメージリーダーの数は1つで、num_threads 64に変更されません。そして、image_batchは十分に速くは埋めることができないので、image_batchがデキューされていて空の場合、プログラムは早すぎて停止します。

この問題を解決する正しい方法は、Reading Dataに記載されているイメージリーダー(複数の同一サブグラフ)の数を増やすことです。

image_list = [read_image(image_file_dequeue) for _ in range(num_readers)] 
image_batch = tf.train.batch_join(image_list, ...) 
関連する問題