TensorFlow:string_input_producer输出字符串与shuffle = False不一致

时间:2017-10-03 10:30:39

标签: tensorflow

我有2个文件名列表,如filenames_L = [1a,2a,3a,4a,...]和filenames_R = [1b,2b,3b,4b,...],我使用下面的代码制作2个队列。

        """queue for left images"""
        filenames_L = reader.file_name('stereo_dataset/fly_frames_cleanpass/TRAIN', 'Left', 'png')
        png = filenames_L[0].lower().endswith('png')  # If first file is a png, assume they all are
        filenames_L = tf.convert_to_tensor(filenames_L)
        filename_queue_L = tf.train.string_input_producer(filenames_L, shuffle=False, num_epochs=FLAGS.epoch)
        reader_L = tf.WholeFileReader()
        name_L, img_bytes_L = reader_L.read(filename_queue_L)
        image_L = tf.image.decode_png(img_bytes_L, channels=3) if png else tf.image.decode_jpeg(img_bytes_L, channels=3)
        processed_image_L = image_preprocessing_fn(image_L, FLAGS.height, FLAGS.width)
        processed_images_L = tf.train.batch([processed_image_L], FLAGS.batch_size, dynamic_pad=True)

        """queue for right images"""
        filenames_R = reader.file_name('stereo_dataset/fly_frames_cleanpass/TRAIN', 'Right', 'png')
        filenames_R = tf.convert_to_tensor(filenames_R)
        filename_queue_R = tf.train.string_input_producer(filenames_R, shuffle=False, num_epochs=FLAGS.epoch)
        reader_R = tf.WholeFileReader()
        name_R, img_bytes_R = reader_R.read(filename_queue_R)
        image_R = tf.image.decode_png(img_bytes_R, channels=3) if png else tf.image.decode_jpeg(img_bytes_R, channels=3)
        processed_image_R = image_preprocessing_fn(image_R, FLAGS.height, FLAGS.width)
        processed_images_R = tf.train.batch([processed_image_R], FLAGS.batch_size, dynamic_pad=True)

然后我使用下面的代码来获取他们的名字。

    with tf.Session(config=config) as sess:
        sess.run([tf.global_variables_initializer(), tf.local_variables_initializer()])
        coord = tf.train.Coordinator()
        threads = tf.train.start_queue_runners(coord=coord)
        start_time = time.time()
        while not coord.should_stop():
              _, loss_t, step, name_Left, name_Right = sess.run([train_op, loss, global_step, name_L, name_R], feed_dict={disparity_map: disparity})

我从name_Left得到的,name_Right是(3a,3b),(5a,5b)....但我期望它输出像(1a,1b),(2a​​,2b)......

1 个答案:

答案 0 :(得分:0)

我在使用 tf.train.batch tf.train.shuffle_batch 时遇到了类似的问题。

问题出在线程的使用上(类似于:https://github.com/tensorflow/tensorflow/issues/410)。 我只设置了一个线程就解决了。当我这样做时,订单被保留。