使用Tensorflow的Estimator API,在管道的哪个阶段应该执行数据增强?
根据Tensorflow官方指南,可以在input_fn中执行数据增强。具体请参考这里。
根据Tensorflow官方指南,可以在input_fn中执行数据增强。具体请参考这里。
def parse_fn(example):
"Parse TFExample records and perform simple data augmentation."
example_fmt = {
"image": tf.FixedLengthFeature((), tf.string, ""),
"label": tf.FixedLengthFeature((), tf.int64, -1)
}
parsed = tf.parse_single_example(example, example_fmt)
image = tf.image.decode_image(parsed["image"])
# augments image using slice, reshape, resize_bilinear
# |
# |
# |
# v
image = _augment_helper(image)
return image, parsed["label"]
def input_fn():
files = tf.data.Dataset.list_files("/path/to/dataset/train-*.tfrecord")
dataset = files.interleave(tf.data.TFRecordDataset)
dataset = dataset.map(map_func=parse_fn)
# ...
return dataset
我的问题
如果我在input_fn
内执行数据增强,那么parse_fn
会返回一个只包含原始输入图像和所有增强变体的批次还是单个[增强的]示例?如果它只应返回单个[增强的]示例,那么如何确保数据集中的所有图像都以其未增强的形式使用,以及所有变体?