在张量流队列中加载图像提供随机图像而不是FIFO

时间:2017-04-13 17:56:34

标签: python tensorflow

我正在尝试使用tensorflow加载图像,但我需要文件按顺序排列。当我加载图像时,它会加载一个随机图像,但不是按照我通过初始数组提供的顺序。但是,我的理解是string_input_producer(file_names)是FIFO。为什么我的图像是随机的,如何按顺序加载图像?

with open("name.json", 'r') as f:
    data = json.load(f)
    file_names = []
    for i, row in enumerate(data):
        load_location = row['location']
        file_names.append(load_location)

    filename_queue = tf.train.string_input_producer(file_names) #  list of files to read
    count_num_files = tf.size(file_names)


    reader=tf.WholeFileReader()
    key,value=reader.read(filename_queue)
    img = tf.image.decode_png(value)

    init = tf.global_variables_initializer()
    with tf.Session() as sess:
        sess.run(init)
        coord = tf.train.Coordinator()
        threads = tf.train.start_queue_runners(coord=coord)
        num_files = sess.run(count_num_files)
        for i in range(num_files):
            # this does not match
            location = file_names[i]
            # with this image
            image_eval=img.eval()
    coord.request_stop()
    coord.join(threads)

1 个答案:

答案 0 :(得分:1)

愚蠢的错误,string_input_producer shuffle设置默认为True:

filename_queue = tf.train.string_input_producer(file_names, shuffle=False)