<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v2.15.0/keras/preprocessing/image.py#L58-L178) |

Base class for image data iterators.

Inherits From: [`Sequence`](https://www.tensorflow.org/versions/r2.15/api_docs/python/tf/keras/utils/Sequence)

    tf.keras.preprocessing.image.Iterator(
        n, batch_size, shuffle, seed
    )

> [!WARNING]
> **Deprecated:** [`tf.keras.preprocessing.image.Iterator`](https://www.tensorflow.org/versions/r2.15/api_docs/python/tf/keras/preprocessing/image/Iterator) is not recommended for new code. Prefer loading images with [`tf.keras.utils.image_dataset_from_directory`](https://www.tensorflow.org/versions/r2.15/api_docs/python/tf/keras/utils/image_dataset_from_directory) and transforming the output [`tf.data.Dataset`](https://www.tensorflow.org/versions/r2.15/api_docs/python/tf/data/Dataset) with preprocessing layers. For more information, see the tutorials for [loading images](https://www.tensorflow.org/tutorials/load_data/images) and [augmenting images](https://www.tensorflow.org/tutorials/images/data_augmentation), as well as the [preprocessing layer guide](https://www.tensorflow.org/guide/keras/preprocessing_layers).

Every `Iterator` must implement the `_get_batches_of_transformed_samples`
method.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `n` | Integer, total number of samples in the dataset to loop over. |
| `batch_size` | Integer, size of a batch. |
| `shuffle` | Boolean, whether to shuffle the data between epochs. |
| `seed` | Random seeding for data shuffling. |

<br />

## Methods

### `next`

[View source](https://github.com/keras-team/keras/tree/v2.15.0/keras/preprocessing/image.py#L158-L168)

    next()

For python 2.x.

<br />

<br />

<br />

| Returns ||
|---|---|
| The next batch. ||

<br />

### `on_epoch_end`

[View source](https://github.com/keras-team/keras/tree/v2.15.0/keras/preprocessing/image.py#L121-L122)

    on_epoch_end()

Method called at the end of every epoch.

### `reset`

[View source](https://github.com/keras-team/keras/tree/v2.15.0/keras/preprocessing/image.py#L124-L125)

    reset()

### `__getitem__`

[View source](https://github.com/keras-team/keras/tree/v2.15.0/keras/preprocessing/image.py#L101-L116)

    __getitem__(
        idx
    )

Gets batch at position `index`.

<br />

<br />

<br />

| Args ||
|---|---|
| `index` | position of the batch in the Sequence. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A batch ||

<br />

### `__iter__`

[View source](https://github.com/keras-team/keras/tree/v2.15.0/keras/preprocessing/image.py#L150-L153)

    __iter__()

Create a generator that iterate over the Sequence.

### `__len__`

[View source](https://github.com/keras-team/keras/tree/v2.15.0/keras/preprocessing/image.py#L118-L119)

    __len__()

Number of batch in the Sequence.

<br />

<br />

<br />

| Returns ||
|---|---|
| The number of batches in the Sequence. ||

<br />

<br />

<br />

<br />

| ## Class Variables ||
|---|---|
| white_list_formats | `('png', 'jpg', 'jpeg', 'bmp', 'ppm', 'tif', 'tiff')` |

<br />