title: Sliding window of a batch in Tensorflow using Dataset API
body: <p>Is there a way to modify the composition of my images within a batch? At the moment, when I'm creating e.g. a batch with the size of 4, my batches will look like that:</p>
  
  <p>Batch1: <code>[Img0 Img1 Img2 Img3]</code>
  Batch2: <code>[Img4 Img5 Img6 Img7]</code></p>
  
  <p>I need to modify the composition of my batches so that it will only shift once to the next image. Then it should look like that:</p>
  
  <p>Batch1: <code>[Img0 Img1 Img2 Img3]</code>
  Batch2: <code>[Img1 Img2 Img3 Img4]</code>
  Batch3: <code>[Img2 Img3 Img4 Img5]</code>
  Batch4: <code>[Img3 Img4 Img5 Img6]</code>
  Batch5: <code>[Img4 Img5 Img6 Img7]</code></p>
  
  <p>I'm using in my code the Dataset API of Tensorflow which looks as follows:</p>
  
  <pre><code>def tfrecords_train_input(input_dir, examples, epochs, nsensors, past, future,
                            features, batch_size, threads, shuffle, record_type):
      filenames = sorted(
          [os.path.join(input_dir, f) for f in os.listdir(input_dir)])
        num_records = 0
        for fn in filenames:
          for _ in tf.python_io.tf_record_iterator(fn):
            num_records += 1
        print("Number of files to use:", len(filenames), "/ Total records to use:", num_records)
        dataset = tf.data.TFRecordDataset(filenames)
        # Parse records
        read_proto = partial(record_type().read_proto, nsensors=nsensors, past=past,
                             future=future, features=features)
        # Parallelize Data Transformation on available GPU
        dataset = dataset.map(map_func=read_proto, num_parallel_calls=threads)
        # Cache data
        dataset = dataset.cache()
        # repeat after shuffling
        dataset = dataset.repeat(epochs)
        # Batch data
        dataset = dataset.batch(batch_size)
        # Efficient Pipelining
        dataset = dataset.prefetch(2)
        iterator = dataset.make_one_shot_iterator()
        return iterator
  </code></pre>