我今天遇到了完全相同的问题,后来我发现它是我从“著名数据集”(例如https://archive.ics.uci.edu/ml/machine-learning-databases/iris/导致错误的iris.data ):文件末尾有一些空行。删除空行,错误消失了!

TensorFlow random_shuffle_queue已关闭且元素不足

共 5 个回答
高赞
时间
活跃
0

0

您可能错误地处理了已解析的TFRecord示例。例如,尝试将张量整形为不兼容的大小。您可以使用tf_record_iterator进行调试,以确认所读取的数据以您认为的方式存储:
import tensorflow as tf
import numpy as np
tfrecords_filename = '/path/to/some.tfrecord'
record_iterator = tf.python_io.tf_record_iterator(path=tfrecords_filename)
for string_record in record_iterator:
# Parse the next example
example = tf.train.Example()
example.ParseFromString(string_record)
# Get the features you stored (change to match your tfrecord writing code)
height = int(example.features.feature['height']
.int64_list
.value[0])
width = int(example.features.feature['width']
.int64_list
.value[0])
img_string = (example.features.feature['image_raw']
.bytes_list
.value[0])
# Convert to a numpy array (change dtype to the datatype you stored)
img_1d = np.fromstring(img_string, dtype=np.float32)
# Print the image shape; does it match your expectations?
print(img_1d.shape)
0

我有一个类似的问题。在网上浏览时发现,如果您使用一些num_epochs
参数,则必须初始化所有local
变量,因此您的代码应最终看起来像:
with tf.Session() as sess:
sess.run(tf.local_variables_initializer())
sess.run(tf.global_variables_initializer())
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord)
# do your stuff here
coord.request_stop()
coord.join(threads)
如果您发布更多代码,也许我可以更深入地研究它。同时,HTH。
0

总结评论,
Compute status: Out of range: RandomSuffleQueue '_2_input/shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0)
是由于队列中的数据用完了。这通常是由于您认为您只有足够的数据用于N次迭代,而实际上您只有足够的M次迭代(其中M <N)。
弄清楚您实际上有多少数据的一种建议是,在队列抛出OutOfRangeError异常之前,计算可以读取的数据次数。
0

这也可能是由于根本不存在错误的tf记录文件名引起的。在进行其他检查之前,请确保指定了正确的文件路径。
新手导航
- 社区规范
- 提出问题
- 进行投票
- 个人资料
- 优化问题
- 回答问题
0
我正在通过从tfrecords获取想法来读取一批图像(由this转换)
我的图像是cifar图像[32、32、3],正如您在读取和传递图像时所看到的,形状是正常的(
batch_size=100
)据我所知,日志中指出的2个最值得注意的问题是
Compute status: Out of range: RandomSuffleQueue '_2_input/shuffle_batch/random_shuffle_queue' is closed and has insufficient elements (requested 100, current size 0)
我该如何解决?
日志: