# tf.compat.v1.train.limit_epochs

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.14.0/tensorflow/python/training/input.py#L79-L112) |

Returns tensor `num_epochs` times and then raises an `OutOfRange` error. (deprecated)

    tf.compat.v1.train.limit_epochs(
        tensor, num_epochs=None, name=None
    )

> [!WARNING]
> **Deprecated:** 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/r2.14/api_docs/python/tf/data). Use `tf.data.Dataset.from_tensors(tensor).repeat(num_epochs)`.

> [!NOTE]
> **Note:** creates local counter `epochs`. Use `local_variables_initializer()` to initialize local variables.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `tensor` | Any `Tensor`. |
| `num_epochs` | A positive integer (optional). If specified, limits the number of steps the output tensor may be evaluated. |
| `name` | A name for the operations (optional). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| tensor or `OutOfRange`. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | if `num_epochs` is invalid. |

<br />