title: How to perform data augmentation in Tensorflow Estimator's input_fn
body: <p>Using Tensorflow's Estimator API, at what point in the pipeline should I perform the data augmentation?</p>
  
  <p>According to this official <a href="https://www.tensorflow.org/performance/datasets_performance" rel="nofollow noreferrer">Tensorflow guide</a>, one place to perform the data augmentation is in the <code>input_fn</code>:</p>
  
  <pre><code>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
  </code></pre>
  
  <h1>My question</h1>
  
  <p>If I perform data augmentation inside <code>input_fn</code>, does <code>parse_fn</code> return a single example or a batch including the original input image + all of the augmented variants? If it should only return a single [augmented] example, how do I ensure that all images in the dataset are used in its un-augmented form, as well as all variants?</p>