# tf.contrib.eager.Iterator

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/eager/python/datasets.py#L27-L75) |

An iterator producing tf.Tensor objects from a tf.data.Dataset.

    tf.contrib.eager.Iterator(
        dataset
    )

> [!NOTE]
> **Note:** Unlike the iterator created by the [`tf.data.Dataset.make_one_shot_iterator`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/data/Dataset#make_one_shot_iterator) method, this class enables additional experimental functionality, such as prefetching to the GPU.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `dataset` | A [`tf.data.Dataset`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/data/Dataset) object. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `TypeError` | If `dataset` is an unsupported type. |
| `RuntimeError` | When invoked without eager execution enabled. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `element_spec` | The type specification of an element of this iterator. |
| `output_classes` | Returns the class of each component of an element of this iterator. (deprecated) <br /> > [!WARNING] > **Warning:** THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use [`tf.compat.v1.data.get_output_classes(iterator)`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/data/get_output_classes). The expected values are [`tf.Tensor`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/Tensor) and [`tf.SparseTensor`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/sparse/SparseTensor). |
| `output_shapes` | Returns the shape of each component of an element of this iterator. (deprecated) <br /> > [!WARNING] > **Warning:** THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use [`tf.compat.v1.data.get_output_shapes(iterator)`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/data/get_output_shapes). |
| `output_types` | Returns the type of each component of an element of this iterator. (deprecated) > [!WARNING] > **Warning:** THIS FUNCTION IS DEPRECATED. It will be removed in a future version. Instructions for updating: Use [`tf.compat.v1.data.get_output_types(iterator)`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/data/get_output_types). |

## Methods

### `get_next`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/data/ops/iterator_ops.py#L724-L737)

    get_next(
        name=None
    )

Returns a nested structure of [`tf.Tensor`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/Tensor)s containing the next element.

<br />

<br />

<br />

| Args ||
|---|---|
| `name` | (Optional.) A name for the created operation. Currently unused. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A nested structure of [`tf.Tensor`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/Tensor) objects. ||

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| [`tf.errors.OutOfRangeError`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/errors/OutOfRangeError): If the end of the dataset has been reached. ||

<br />

### `next`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/data/ops/iterator_ops.py#L663-L668)

    next()

Returns a nested structure of `Tensor`s containing the next element.

### `__iter__`

[View source](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/python/data/ops/iterator_ops.py#L618-L619)

    __iter__()