tf.raw_ops.WindowDataset
Stay organized with collections
Save and categorize content based on your preferences.
Combines (nests of) input elements into a dataset of (nests of) windows.
tf.raw_ops.WindowDataset(
input_dataset,
size,
shift,
stride,
drop_remainder,
output_types,
output_shapes,
metadata='',
name=None
)
A "window" is a finite dataset of flat elements of size size
(or possibly
fewer if there are not enough input elements to fill the window and
drop_remainder
evaluates to false).
The shift
argument determines the number of input elements by which
the window moves on each iteration. The first element in the k
th window
will be element
1 + (k-1) * shift
of the input dataset. In particular, the first element of the first window
will always be the first element of the input dataset.
If the stride
parameter is greater than 1, then each window will skip
(stride - 1)
input elements between each element that appears in the
window. Output windows will still contain size
elements regardless of
the value of stride
.
The stride
argument determines the stride of the input elements, and the
shift
argument determines the shift of the window.
For example, letting {...}
to represent a Dataset:
tf.data.Dataset.range(7).window(2)
produces
{ {0, 1}, {2, 3}, {4, 5}, {6} }
tf.data.Dataset.range(7).window(3, 2, 1, True)
produces
{ {0, 1, 2}, {2, 3, 4}, {4, 5, 6} }
tf.data.Dataset.range(7).window(3, 1, 2, True)
produces
{ {0, 2, 4}, {1, 3, 5}, {2, 4, 6} }
Note that when the window
transformation is applied to a dataset of
nested elements, it produces a dataset of nested windows.
For example:
tf.data.Dataset.from_tensor_slices((range(4), range(4))).window(2)
produces {({0, 1}, {0, 1}), ({2, 3}, {2, 3})}
tf.data.Dataset.from_tensor_slices({"a": range(4)}).window(2)
produces { {"a": {0, 1} }, {"a": {2, 3} } }
Args |
input_dataset
|
A Tensor of type variant .
|
size
|
A Tensor of type int64 .
An integer scalar, representing the number of elements
of the input dataset to combine into a window. Must be positive.
|
shift
|
A Tensor of type int64 .
An integer scalar, representing the number of input elements
by which the window moves in each iteration. Defaults to size .
Must be positive.
|
stride
|
A Tensor of type int64 .
An integer scalar, representing the stride of the input elements
in the sliding window. Must be positive. The default value of 1 means
"retain every input element".
|
drop_remainder
|
A Tensor of type bool .
A Boolean scalar, representing whether the last window should be
dropped if its size is smaller than window_size .
|
output_types
|
A list of tf.DTypes that has length >= 1 .
|
output_shapes
|
A list of shapes (each a tf.TensorShape or list of ints ) that has length >= 1 .
|
metadata
|
An optional string . Defaults to "" .
|
name
|
A name for the operation (optional).
|
Returns |
A Tensor of type variant .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[null,null,["Last updated 2024-04-26 UTC."],[],[],null,["# tf.raw_ops.WindowDataset\n\n\u003cbr /\u003e\n\nCombines (nests of) input elements into a dataset of (nests of) windows.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.raw_ops.WindowDataset`](https://www.tensorflow.org/api_docs/python/tf/raw_ops/WindowDataset)\n\n\u003cbr /\u003e\n\n tf.raw_ops.WindowDataset(\n input_dataset,\n size,\n shift,\n stride,\n drop_remainder,\n output_types,\n output_shapes,\n metadata='',\n name=None\n )\n\nA \"window\" is a finite dataset of flat elements of size `size` (or possibly\nfewer if there are not enough input elements to fill the window and\n`drop_remainder` evaluates to false).\n\nThe `shift` argument determines the number of input elements by which\nthe window moves on each iteration. The first element in the `k`th window\nwill be element \n\n 1 + (k-1) * shift\n\nof the input dataset. In particular, the first element of the first window\nwill always be the first element of the input dataset.\n\nIf the `stride` parameter is greater than 1, then each window will skip\n`(stride - 1)` input elements between each element that appears in the\nwindow. Output windows will still contain `size` elements regardless of\nthe value of `stride`.\n\nThe `stride` argument determines the stride of the input elements, and the\n`shift` argument determines the shift of the window.\n\nFor example, letting `{...}` to represent a Dataset:\n\n- `tf.data.Dataset.range(7).window(2)` produces `{ {0, 1}, {2, 3}, {4, 5}, {6} }`\n- `tf.data.Dataset.range(7).window(3, 2, 1, True)` produces `{ {0, 1, 2}, {2, 3, 4}, {4, 5, 6} }`\n- `tf.data.Dataset.range(7).window(3, 1, 2, True)` produces `{ {0, 2, 4}, {1, 3, 5}, {2, 4, 6} }`\n\nNote that when the `window` transformation is applied to a dataset of\nnested elements, it produces a dataset of nested windows.\n\n#### For example:\n\n- `tf.data.Dataset.from_tensor_slices((range(4), range(4))).window(2)` produces `{({0, 1}, {0, 1}), ({2, 3}, {2, 3})}`\n- `tf.data.Dataset.from_tensor_slices({\"a\": range(4)}).window(2)` produces `{ {\"a\": {0, 1} }, {\"a\": {2, 3} } }`\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `input_dataset` | A `Tensor` of type `variant`. |\n| `size` | A `Tensor` of type `int64`. An integer scalar, representing the number of elements of the input dataset to combine into a window. Must be positive. |\n| `shift` | A `Tensor` of type `int64`. An integer scalar, representing the number of input elements by which the window moves in each iteration. Defaults to `size`. Must be positive. |\n| `stride` | A `Tensor` of type `int64`. An integer scalar, representing the stride of the input elements in the sliding window. Must be positive. The default value of 1 means \"retain every input element\". |\n| `drop_remainder` | A `Tensor` of type `bool`. A Boolean scalar, representing whether the last window should be dropped if its size is smaller than `window_size`. |\n| `output_types` | A list of `tf.DTypes` that has length `\u003e= 1`. |\n| `output_shapes` | A list of shapes (each a [`tf.TensorShape`](../../tf/TensorShape) or list of `ints`) that has length `\u003e= 1`. |\n| `metadata` | An optional `string`. Defaults to `\"\"`. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor` of type `variant`. ||\n\n\u003cbr /\u003e"]]