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.
[null,null,["Last updated 2024-09-20 UTC."],[],[],null,["# tff.analytics.data_processing.to_stacked_tensor\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/federated/blob/v0.87.0 Version 2.0, January 2004 Licensed under the Apache License, Version 2.0 (the) |\n\nEncodes the \\`tf.data.Dataset as stacked tensors. \n\n @tf.function\n tff.analytics.data_processing.to_stacked_tensor(\n ds: tf.data.Dataset\n ) -\u003e tf.Tensor\n\nThis is effectively the inverse of [`tf.data.Dataset.from_tensor_slices()`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset#from_tensor_slices).\nAll elements from the input dataset are concatenated into a tensor structure,\nwhere the output structure matches the input `ds.element_spec`, and each\noutput tensor will have the same shape plus one additional prefix dimension\nwhich elements are stacked in. For example, if the dataset contains 5\nelements with shape \\[3, 2\\], the returned tensor will have shape \\[5, 3, 2\\].\nNote that each element in the dataset could be as single tensor or a structure\nof tensors.\n\nDataset elements must have fully-defined shapes. Any partially-defined element\nshapes will raise an error. If passing in a batched dataset, use\n`drop_remainder=True` to ensure the batched shape is fully defined.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------|-----------------------------------------------------------------------------------------------------|\n| `ds` | The input [`tf.data.Dataset`](https://www.tensorflow.org/api_docs/python/tf/data/Dataset) to stack. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A structure of tensors encoding the input dataset. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|----------------------------------------------------|\n| `ValueError` | If any dataset element shape is not fully-defined. |\n\n\u003cbr /\u003e"]]