title: How to combine multiple tfrecord datasets into one dataset?
body: <p><strong>Suppose I have 3 tfrecord files, namely <code>neg.tfrecord</code>, <code>pos1.tfrecord</code>, <code>pos2.tfrecord</code>.</strong></p>
  
  <p><strong>My batch size is 500, including 300 neg data, 100 pos1 data, and 100 pos2 data. How can I get the desired TFRecordDataset?</strong></p>
  
  <p>I will use this TFRecordDataset object in keras.fit() (Eager Execution).</p>
  
  <p>My tensorflow's version is 1.13.1. I find the API in <a href="https://www.tensorflow.org/api_docs/python/tf/data/Dataset" rel="nofollow noreferrer">tf.data.Dataset</a>, such as <code>interleave</code>, <code>concatenate</code>, <code>zip</code>, but it seems that I can't solve my problem.</p>
  
  <p>Before, I tried to get the iterator for each dataset, and then manually concat after getting the data, but it was inefficient and the GPU utilization was not high.</p>
  
  <p>And in this <a href="https://stackoverflow.com/questions/55154836/how-to-combine-multiple-datasets-into-one-dataset/55155937?noredirect=1#comment97059416_55155937">question</a>, I use <code>interleave</code> below:</p>
  
  <pre class="lang-py prettyprint-override"><code>tfrecord_files = ['neg.tfrecord', 'pos1.tfrecord', 'pos2.tfrecord']
  dataset = tf.data.Dataset.from_tensor_slices(tfrecord_files)
  def _parse(x):
      x = tf.data.TFRecordDataset(x)
      return x
  dataset = dataset.interleave(_parse, cycle_length=4, block_length=1)
  dataset = dataset.apply(tf.data.experimental.map_and_batch(_parse_image_function, 500))
  </code></pre>
  
  <p>and I got this batch:</p>
  
  <pre><code>neg pos1 pos2 neg pos1 pos2 ...............
  </code></pre>
  
  <p>But what I want is this:</p>
  
  <pre><code>neg neg neg pos1 pos2 neg neg neg pos1 pos2 .................
  </code></pre>
  
  <p>What I should do?</p>
  
  <p>Looking forward to answering.</p>