Missed TensorFlow World? Check out the recap. Learn more



Defined in tensorflow/contrib/data/python/ops/sliding.py.

A sliding window with size of window_size and step of stride.

This transformation passes a sliding window over this dataset. The window size is window_size and step size is stride. If the left elements cannot fill up the sliding window, this transformation will drop the final smaller element. For example:

# NOTE: The following examples use `{ ... }` to represent the
# contents of a dataset.
a = { [1], [2], [3], [4], [5], [6] }

a.apply(tf.contrib.data.sliding_window_batch(window_size=3, stride=2)) ==
    [[1], [2], [3]],
    [[3], [4], [5]],


  • window_size: A tf.int64 scalar tf.Tensor, representing the number of elements in the sliding window.
  • stride: (Optional.) A tf.int64 scalar tf.Tensor, representing the steps moving the sliding window forward for one iteration. The default is 1. It must be positive.


A Dataset transformation function, which can be passed to tf.data.Dataset.apply.