2017-03-06 5 views
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は実行されませんでした。

+0

最初のキューランナーを開始するためにどのキューランナーをチェックするために使用されるものですtf.GraphKeys.QUEUE_RUNNERSコレクションに追加されているので - https://github.com/tensorflow/tensorflow/blob/1708b92bb923e420d746a56baafc7d4ddcd5e05e/tensorflow/python /training/queue_runner_impl.py#L365 –

+0

また、2番目のキューランナーは何も参照されないため、sess.runの前にPythonによってガベージコレクションが行われます。 –

+0

@YaroslavBulatov QUEUE_RUNNERSコレクションに追加されない(2番目のQR)暗黙のうちに? – Priyatham

答えて

0

キューランナーは暗黙的にtf.GraphKeys.QUEUE_RUNNERSに追加されません。

qr = tf.train.QueueRunner(image_queue, [enqueue_op] * 2) 
tf.train.add_queue_runner(qr) 

tf.train.start_queue_runnersを呼び出すと、あまりにもこのキューランナー(qr)を開始します:任意のQueueRunnerあなたはこれがそれを修正する必要がありtf.train.add_queue_runner

を使用して作成を追加します。

関連する問題