gpt4 book ai didi

machine-learning - Tensorflow:分离 TFRecords 中的训练和评估数据

转载 作者:行者123 更新时间:2023-11-30 08:37:14 25 4
gpt4 key购买 nike

我有一个充满标签数据的 .tfrecords 文件。我想使用其中的 X% 进行训练,使用 (1-X)% 进行评估/测试。显然不应该有任何重叠。最好的方法是什么?

下面是我用于读取tfrecords的小代码块。有什么方法可以让 shuffle_batch 将数据拆分为训练数据和评估数据吗?我是否错误地处理了这个问题?

reader = tf.TFRecordReader()
files = tf.train.string_input_producer([TFRECORDS_FILE], num_epochs=num_epochs)

read_name, serialized_examples = reader.read(files)
features = tf.parse_single_example(
serialized = serialized_examples,
features={
'image': tf.FixedLenFeature([], tf.string),
'value': tf.FixedLenFeature([], tf.string),
})
image = tf.decode_raw(features['image'], tf.uint8)
value = tf.decode_raw(features['value'], tf.uint8)

image, value = tf.train.shuffle_batch([image, value],
enqueue_many = False,
batch_size = 4,
capacity = 30,
num_threads = 3,
min_after_dequeue = 10)

最佳答案

虽然这个问题是一年多前提出的,但我最近也有类似的问题。

我在输入哈希上使用了 tf.data.Dataset 和过滤器。这是一个示例:

dataset = tf.data.TFRecordDataset(files)

if is_evaluation:
dataset = dataset.filter(
lambda r: tf.string_to_hash_bucket_fast(r, 10) == 0)
else:
dataset = dataset.filter(
lambda r: tf.string_to_hash_bucket_fast(r, 10) != 0)

dataset = dataset.map(tf.parse_single_example)

return dataset

到目前为止我注意到的缺点之一是每次评估可能需要 10 倍的数据遍历才能收集足够的数据。为了避免这种情况,您可能需要在数据预处理时分离数据。

关于machine-learning - Tensorflow:分离 TFRecords 中的训练和评估数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42889060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com