# tf.train.maybe_shuffle_batch

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/training/input.py#L1350-L1411) |

Creates batches by randomly shuffling conditionally-enqueued tensors. (deprecated)

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.train.maybe_shuffle_batch`](https://www.tensorflow.org/api_docs/python/tf/compat/v1/train/maybe_shuffle_batch)

<br />

    tf.train.maybe_shuffle_batch(
        tensors, batch_size, capacity, min_after_dequeue, keep_input, num_threads=1,
        seed=None, enqueue_many=False, shapes=None, allow_smaller_final_batch=False,
        shared_name=None, name=None
    )

> [!WARNING]
> **Warning:** THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Queue-based input pipelines have been replaced by [`tf.data`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/data). Use `tf.data.Dataset.filter(...).shuffle(min_after_dequeue).batch(batch_size)`.

See docstring in `shuffle_batch` for more details.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `tensors` | The list or dictionary of tensors to enqueue. |
| `batch_size` | The new batch size pulled from the queue. |
| `capacity` | An integer. The maximum number of elements in the queue. |
| `min_after_dequeue` | Minimum number elements in the queue after a dequeue, used to ensure a level of mixing of elements. |
| `keep_input` | A `bool` Tensor. This tensor controls whether the input is added to the queue or not. If it is a scalar and evaluates `True`, then `tensors` are all added to the queue. If it is a vector and `enqueue_many` is `True`, then each example is added to the queue only if the corresponding value in `keep_input` is `True`. This tensor essentially acts as a filtering mechanism. |
| `num_threads` | The number of threads enqueuing `tensor_list`. |
| `seed` | Seed for the random shuffling within the queue. |
| `enqueue_many` | Whether each tensor in `tensor_list` is a single example. |
| `shapes` | (Optional) The shapes for each example. Defaults to the inferred shapes for `tensor_list`. |
| `allow_smaller_final_batch` | (Optional) Boolean. If `True`, allow the final batch to be smaller if there are insufficient items left in the queue. |
| `shared_name` | (Optional) If set, this queue will be shared under the given name across multiple sessions. |
| `name` | (Optional) A name for the operations. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A list or dictionary of tensors with the types as `tensors`. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If the `shapes` are not specified, and cannot be inferred from the elements of `tensors`. |

<br />

#### Eager Compatibility

Input pipelines based on Queues are not supported when eager execution is
enabled. Please use the [`tf.data`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/data) API to ingest data under eager execution.