OutOfRangeError(回溯见上文):RandomShuffleQueue '_5_shuffle_batch_1/random_shuffle_queue' 已关闭且元素不足 [英] OutOfRangeError (see above for traceback): RandomShuffleQueue '_5_shuffle_batch_1/random_shuffle_queue' is closed and has insufficient elements

查看:30
本文介绍了OutOfRangeError(回溯见上文):RandomShuffleQueue '_5_shuffle_batch_1/random_shuffle_queue' 已关闭且元素不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 TFrecord 作为输入.
现在我需要三重批量输入.image_batchlabel_batch 没问题.但是第二个 posimage_batch, poslabel_batch 是错误的.我已经阅读了很多关于 RandomShuffleQueue 错误问题的帖子.
答案 tf.local_variables_initializer() 不能解决我的错误
因为我只搜索一个 batch_databatch_label 作为输入.所以我不知道三重输入.
我在网上找了很久.但是没有用.请帮助或尝试提供一些如何实现这一目标的想法.

I use TFrecord as input.
And now I need triple batch input. The image_batch and label_batch is ok. But second posimage_batch, poslabel_batch is error. I have read many posts about RandomShuffleQueue error question.
The answer tf.local_variables_initializer() doesn't solve my error
Because I search only one batch_data and batch_label as input. So I have no idea about triple input.
I am searching for a long time on net. But no use. Please help or try to give some ideas how to achieve this.

def real_read_and_decode(filename):
    filename_queue = tf.train.string_input_producer([filename])

    reader = tf.TFRecordReader()
    _, serialized_example = reader.read(filename_queue)
    features = tf.parse_single_example(serialized_example,
                                       features={
                                           'label': tf.FixedLenFeature([], tf.int64),
                                           'img_raw' : tf.FixedLenFeature([], tf.string),
                                       })
    img = tf.decode_raw(features['img_raw'], tf.uint8)
    img = tf.reshape(img, [WIDTH,HEIGHT, 3])
    label = tf.cast(features['label'], tf.int32)
    labels = tf.one_hot(label, NUM_CLASSES)
    return img, labels    

def main():

    image, label = read_and_decode("sketch_train.tfrecords")
    posimage, poslabel = real_read_and_decode("pos_train.tfrecords")
    negimage, neglabel = real_read_and_decode("neg_train.tfrecords")

    image_batch, label_batch =tf.train.shuffle_batch([image, label],batch_size=BATCH_SIZE,capacity=1500, min_after_dequeue=1000)
    posimage_batch, poslabel_batch = tf.train.shuffle_batch([posimage, poslabel],batch_size=BATCH_SIZE,capacity=1500, min_after_dequeue=1000)
    negimage_batch, neglabel_batch = tf.train.shuffle_batch([negimage, neglabel],batch_size=BATCH_SIZE,capacity=1500, min_after_dequeue=1000)

    with tf.Session(config=config) as sess:
        sess.run(tf.local_variables_initializer())
        sess.run(tf.global_variables_initializer())
        coord = tf.train.Coordinator()
        threads = tf.train.start_queue_runners(sess=sess,coord=coord)
        for i in range(ITERATION):
            if coord.should_stop():
                print('corrd break!!!!!!')
                break
            #sess.run(tf.local_variables_initializer())
            example_train, l_train = sess.run([image_batch, label_batch])
            example_train2, l_train2= sess.run([posimage_batch, poslabel_batch])
            example_train3, l_train3 = sess.run([negimage_batch, neglabel_batch])
            _, loss_v = sess.run([train_step, loss],feed_dict={x1: example_train,y1: l_train,x2: example_train2, y2: l_train2,x3: example_train3, y3: l_train3})

这是我的日志

因为我是新用户,我的英语不好.
希望你不要介意.

Because I am a new user, and my english is not good.
Hope you don't mind.

推荐答案

您可能只需要添加一些对 OutOfRangeError 异常的处理,该异常预计迟早会发生:

You probably just need to add some handling of the OutOfRangeError exception which is expected to happen sooner or later:

try:
    sess.run(tf.local_variables_initializer())
    sess.run(tf.global_variables_initializer())
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(sess=sess,coord=coord)
    for i in range(ITERATION):
    #....
except tf.errors.OutOfRangeError:
    print('Done training -- limit reached')
finally:
    coord.request_stop()

这篇关于OutOfRangeError(回溯见上文):RandomShuffleQueue '_5_shuffle_batch_1/random_shuffle_queue' 已关闭且元素不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆