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)