【问题标题】:Tensorflow: Separating Training and Evaluation Data in TFRecordsTensorflow:在 TFRecords 中分离训练和评估数据
【发布时间】:2017-03-19 16:28:22
【问题描述】:

我有一个.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)

【问题讨论】:

    标签: machine-learning tensorflow training-data


    【解决方案1】:

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

    我在输入哈希上使用了带有过滤器的 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 倍的数据遍历才能收集足够的数据。为避免这种情况,您可能希望在数据预处理时分离数据。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-05
      • 1970-01-01
      • 1970-01-01
      • 2021-01-02
      • 2023-04-06
      • 1970-01-01
      • 2013-07-04
      • 1970-01-01
      相关资源
      最近更新 更多