tf.keras.ops.extract_sequences
Stay organized with collections
Save and categorize content based on your preferences.
Expands the dimension of last axis into sequences of sequence_length
.
tf.keras.ops.extract_sequences(
x, sequence_length, sequence_stride
)
Slides a window of size sequence_length
over the last axis of the input
with a stride of sequence_stride
, replacing the last axis with
[num_sequences, sequence_length]
sequences.
If the dimension along the last axis is N, the number of sequences can be
computed by:
num_sequences = 1 + (N - sequence_length) // sequence_stride
Args |
x
|
Input tensor.
|
sequence_length
|
An integer representing the sequences length.
|
sequence_stride
|
An integer representing the sequences hop size.
|
Returns |
A tensor of sequences with shape [..., num_sequences, sequence_length].
|
Example:
x = keras.ops.convert_to_tensor([1, 2, 3, 4, 5, 6])
extract_sequences(x, 3, 2)
array([[1, 2, 3],
[3, 4, 5]])
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-06-07 UTC.
[null,null,["Last updated 2024-06-07 UTC."],[],[],null,["# tf.keras.ops.extract_sequences\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/ops/math.py#L276-L308) |\n\nExpands the dimension of last axis into sequences of `sequence_length`. \n\n tf.keras.ops.extract_sequences(\n x, sequence_length, sequence_stride\n )\n\nSlides a window of size `sequence_length` over the last axis of the input\nwith a stride of `sequence_stride`, replacing the last axis with\n`[num_sequences, sequence_length]` sequences.\n\nIf the dimension along the last axis is N, the number of sequences can be\ncomputed by:\n\n`num_sequences = 1 + (N - sequence_length) // sequence_stride`\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------------|-------------------------------------------------|\n| `x` | Input tensor. |\n| `sequence_length` | An integer representing the sequences length. |\n| `sequence_stride` | An integer representing the sequences hop size. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A tensor of sequences with shape \\[..., num_sequences, sequence_length\\]. ||\n\n\u003cbr /\u003e\n\n#### Example:\n\n x = keras.ops.convert_to_tensor([1, 2, 3, 4, 5, 6])\n extract_sequences(x, 3, 2)\n array([[1, 2, 3],\n [3, 4, 5]])"]]