title: How to expand tf.data.Dataset with additional example transformations in Tensorflow
body: <p>I would like to double the size of an existing dataset I'm using to train a neural network in tensorflow on the fly by adding random noise to it. So when I'm done I'll have all the existing examples and also all the examples with noise added to them. I'd also like to interleave these as I transform them, so they come out in this order: example 1 without noise, example 1 with noise, example 2 without noise, example 2 with noise, etc. I'm struggling to accomplish this using the Dataset api. I've tried to use unbatch to accomplish this like so:</p>
  
  <pre><code>def generate_permutations(features, labels):
      return [
          [features, labels],
          [add_noise(features), labels]
      ]
  
  dataset.map(generate_permutations).apply(tf.contrib.data.unbatch())
  </code></pre>
  
  <p>but I get an error saying <code>Shapes must be equal rank, but are 2 and 1</code>. I'm guessing tensorflow is trying to make a tensor out of that batch I'm returning, but <code>features</code> and <code>labels</code> are different shapes, so that doesn't work. I could probably do this by just making two datasets and concating them together, but I'm worried that would result in very skewed training where I train nicely for half the epoch and suddenly all of the data has this new transformation to it for the second half. How can I accomplish this on the fly without writing these transformations to disk before feeding into tensorflow?</p>