W3cubDocs

/TensorFlow Python

tf.contrib.data.sliding_window_batch

tf.contrib.data.sliding_window_batch(
    window_size,
    stride=1
)

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]],
}

Args:

  • 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 in [1, window_size).

Returns:

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

© 2018 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/api_docs/python/tf/contrib/data/sliding_window_batch