OutOfRangeError: RandomShuffleQueue '_83_shuffle_batch_7/random_shuffle_queue' is closed and has ins

tensorflow 执行代码时出现以下错误 

OutOfRangeError: RandomShuffleQueue '_83_shuffle_batch_7/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0)
def read_csv(batch_size, filename, record_defaults):
    filename_queue = tf.train.string_input_producer([filename])
    reader = tf.TextLineReader(skip_header_lines=1)
    key, value = reader.read(filename_queue)
    decoded = tf.decode_csv(value, record_defaults=record_defaults)
    return tf.train.shuffle_batch(decoded,
                                 batch_size=batch_size,
                                 capacity=batch_size * 7,
                                 num_threads=32,
                                 min_after_dequeue=batch_size)

提示是在本代码段处出错,

wrong:
file_path = r"E:\tf_project\练习\train.csv"

wright:
file_path = r"E:\\tf_project\\练习\\train.csv"

最后发现是在读取文件的时候,设置的文件路径有误,因为是在windows下读取,所以采用反斜线,但是发现读取时,必须使用双反斜线才行.

 

还有可能的一种原因是初始化是没有局部变量初始化造成的,如下程序,使用注释掉的那一行初始化方法就没问题了。

import tensorflow as tf

path  = "E:\\tf_project\\练习"

image_filename = path + "\\" + "test-input-image.jpg"
filename_queue = tf.train.string_input_producer(tf.train.match_filenames_once(image_filename))

image_reader = tf.WholeFileReader()
_, image_file = image_reader.read(filename_queue)
image = tf.image.decode_jpeg(image_file)

sess = tf.Session()
#init_op = tf.group(tf.global_variables_initializer(), tf.local_variables_initializer())
init_op = tf.group(tf.global_variables_initializer())

sess.run(init_op)
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord, sess=sess)
print(sess.run(image))
filename_queue.close(cancel_pending_enqueues=True)
coord.request_stop()
coord.join(threads)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值