【发布时间】:2019-01-06 16:59:06
【问题描述】:
使用 Tensorflow 的 Estimator API,我应该在管道中的哪个点执行数据增强?
根据这位官方Tensorflow guide 的说法,执行数据增强的地方在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 会返回单个示例还是包含原始输入图像 + 所有增强变体的批次?如果它应该只返回一个 [augmented] 示例,我如何确保数据集中的所有图像都以其未增强的形式以及所有变体使用?
【问题讨论】:
-
在 .map 中放一个随机函数见stackoverflow.com/questions/55141076/…
标签: tensorflow machine-learning training-data data-augmentation