Dropping/skipping加载数据时记录

Dropping/skipping records when loading data

我在我的训练集中发现了一些错误数据(错误标记的示例),虽然我已经修复了源,但我想继续试验相同的数据集,所以我需要跳过这些记录。

我正在使用 TFRecordReader 并使用 parse_single_example 和 shuffle_batch 进行加载。我可以在某处提供过滤器吗?

docs using tf.train.shuffle_batch() and enqueue_many=True. If you can determine if an example is mislabeled using graph operations, then you can filter the result like so (adapted from ):

中有一个关于如何操作的简短参考
X, y = tf.parse_single_example(...)
is_correctly_labelled = correctly_labelled(X, y)
X = tf.expand_dims(X, 0)
y = tf.expand_dims(y, 0)
empty = tf.constant([], tf.int32)
X, y = tf.cond(is_correctly_labelled,
               lambda: [X, y],
               lambda: [tf.gather(X, empty), tf.gather(y, empty)])
Xs, ys = tf.train.shuffle_batch(
    [X, y], batch_size, capacity, min_after_dequeue,
    enqueue_many=True)

tf.gather 只是一种获取零大小切片的方法。在 numpy 中,它只是 X[[], ...].