On this page
tf.data.experimental.map_and_batch
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. This API is temporary and deprecated since input pipeline optimization now fuses consecutive map and batch operations automatically.
| Args | |
|---|---|
| map_func | A function mapping a nested structure of tensors to another nested structure of tensors. | 
| batch_size | A tf.int64scalartf.Tensor, representing the number of consecutive elements of this dataset to combine in a single batch. | 
| num_parallel_batches | (Optional.) A tf.int64scalartf.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.boolscalartf.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.int32scalartf.Tensor, representing the number of elements to process in parallel. If not specified,batch_size * num_parallel_batcheselements will be processed in parallel. If the valuetf.data.AUTOTUNEis used, then the number of parallel calls is set dynamically based on available CPU. | 
| Returns | |
|---|---|
| A Datasettransformation function, which can be passed totf.data.Dataset.apply. | 
| Raises | |
|---|---|
| ValueError | If both num_parallel_batchesandnum_parallel_callsare specified. | 
© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
 https://www.tensorflow.org/versions/r2.4/api_docs/python/tf/data/experimental/map_and_batch