错误:OutOfRangeError: End of sequence
在用 dataset 训练 CNN 时,采用 tf.data.TFRecordDataset API 处理数据集时报错:OutOfRangeError: End of sequence。
下面是我处理 dataset 的函数:
def get_dataset(train_list, batch_size, epochs=1, shuffle=True):
ds = tf.data.Dataset.from_tensor_slices(train_list) # 载入数据
if shuffle:
ds = ds.shuffle(_NUM_IMAGES_['train'])
ds = ds.map(load_and_preprocess, num_parallel_calls=2)
ds = ds.prefetch(batch_size)
ds = ds.repeat(epochs)
ds = ds.batch

在使用tf.data.TFRecordDataset训练CNN时遇到OutOfRangeError: End of sequence错误。错误发生在迭代器到达数据集末尾时。解决方案包括设置epochs=None使数据无限期重复,或者在达到末尾时重新初始化迭代器。了解Iterator.get_next()的工作原理有助于避免此类问题。建议查阅TensorFlow官方文档深入理解。

5861

被折叠的 条评论
为什么被折叠?



