tff.analytics.data_processing.to_stacked_tensor
Stay organized with collections
Save and categorize content based on your preferences.
Encodes the `tf.data.Dataset as stacked tensors.
@tf.function
tff.analytics.data_processing.to_stacked_tensor(
ds: tf.data.Dataset
) -> tf.Tensor
This is effectively the inverse of tf.data.Dataset.from_tensor_slices()
.
All elements from the input dataset are concatenated into a tensor structure,
where the output structure matches the input ds.element_spec
, and each
output tensor will have the same shape plus one additional prefix dimension
which elements are stacked in. For example, if the dataset contains 5
elements with shape [3, 2], the returned tensor will have shape [5, 3, 2].
Note that each element in the dataset could be as single tensor or a structure
of tensors.
Dataset elements must have fully-defined shapes. Any partially-defined element
shapes will raise an error. If passing in a batched dataset, use
drop_remainder=True
to ensure the batched shape is fully defined.
Returns |
A structure of tensors encoding the input dataset.
|
Raises |
ValueError
|
If any dataset element shape is not fully-defined.
|
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.
Last updated 2024-09-20 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-20 UTC."],[],[]]