tf.data.experimental.map_and_batch
Stay organized with collections
Save and categorize content based on your preferences.
Fused implementation of map
and batch
. (deprecated)
tf.data.experimental.map_and_batch(
map_func, batch_size, num_parallel_batches=None, drop_remainder=False,
num_parallel_calls=None
)
Maps map_func
across batch_size
consecutive elements of this dataset
and then combines them into a batch. Functionally, it is equivalent to map
followed by batch
. However, by fusing the two transformations together, the
implementation can be more efficient. Surfacing this transformation in the API
is temporary. Once automatic input pipeline optimization is implemented,
the fusing of map
and batch
will happen automatically and this API will be
deprecated.
Args |
map_func
|
A function mapping a nested structure of tensors to another
nested structure of tensors.
|
batch_size
|
A tf.int64 scalar tf.Tensor , representing the number of
consecutive elements of this dataset to combine in a single batch.
|
num_parallel_batches
|
(Optional.) A tf.int64 scalar tf.Tensor ,
representing the number of batches to create in parallel. On one hand,
higher values can help mitigate the effect of stragglers. On the other
hand, higher values can increase contention if CPU is scarce.
|
drop_remainder
|
(Optional.) A tf.bool scalar tf.Tensor , representing
whether the last batch should be dropped in case its size is smaller than
desired; the default behavior is not to drop the smaller batch.
|
num_parallel_calls
|
(Optional.) A tf.int32 scalar tf.Tensor ,
representing the number of elements to process in parallel. If not
specified, batch_size * num_parallel_batches elements will be processed
in parallel. If the value tf.data.experimental.AUTOTUNE is used, then
the number of parallel calls is set dynamically based on available CPU.
|
Raises |
ValueError
|
If both num_parallel_batches and num_parallel_calls are
specified.
|
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 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.data.experimental.map_and_batch\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 2 version](/api_docs/python/tf/data/experimental/map_and_batch) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/data/experimental/ops/batching.py#L139-L199) |\n\nFused implementation of `map` and `batch`. (deprecated)\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.data.experimental.map_and_batch`](/api_docs/python/tf/data/experimental/map_and_batch), \\`tf.compat.v2.data.experimental.map_and_batch\\`\n\n\u003cbr /\u003e\n\n tf.data.experimental.map_and_batch(\n map_func, batch_size, num_parallel_batches=None, drop_remainder=False,\n num_parallel_calls=None\n )\n\n| **Warning:** THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use [`tf.data.Dataset.map(map_func, num_parallel_calls)`](../../../tf/data/Dataset#map) followed by [`tf.data.Dataset.batch(batch_size, drop_remainder)`](../../../tf/data/Dataset#batch). Static tf.data optimizations will take care of using the fused implementation.\n\nMaps `map_func` across `batch_size` consecutive elements of this dataset\nand then combines them into a batch. Functionally, it is equivalent to `map`\nfollowed by `batch`. However, by fusing the two transformations together, the\nimplementation can be more efficient. Surfacing this transformation in the API\nis temporary. Once automatic input pipeline optimization is implemented,\nthe fusing of `map` and `batch` will happen automatically and this API will be\ndeprecated.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `map_func` | A function mapping a nested structure of tensors to another nested structure of tensors. |\n| `batch_size` | A [`tf.int64`](../../../tf#int64) scalar [`tf.Tensor`](../../../tf/Tensor), representing the number of consecutive elements of this dataset to combine in a single batch. |\n| `num_parallel_batches` | (Optional.) A [`tf.int64`](../../../tf#int64) scalar [`tf.Tensor`](../../../tf/Tensor), representing the number of batches to create in parallel. On one hand, higher values can help mitigate the effect of stragglers. On the other hand, higher values can increase contention if CPU is scarce. |\n| `drop_remainder` | (Optional.) A [`tf.bool`](../../../tf#bool) scalar [`tf.Tensor`](../../../tf/Tensor), representing whether the last batch should be dropped in case its size is smaller than desired; the default behavior is not to drop the smaller batch. |\n| `num_parallel_calls` | (Optional.) A [`tf.int32`](../../../tf#int32) scalar [`tf.Tensor`](../../../tf/Tensor), representing the number of elements to process in parallel. If not specified, `batch_size * num_parallel_batches` elements will be processed in parallel. If the value [`tf.data.experimental.AUTOTUNE`](../../../tf/data/experimental#AUTOTUNE) is used, then the number of parallel calls is set dynamically based on available CPU. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Dataset` transformation function, which can be passed to [`tf.data.Dataset.apply`](../../../tf/data/Dataset#apply). ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|------------------------------------------------------------------------|\n| `ValueError` | If both `num_parallel_batches` and `num_parallel_calls` are specified. |\n\n\u003cbr /\u003e"]]