tf.keras.preprocessing.image.NumpyArrayIterator
Stay organized with collections
Save and categorize content based on your preferences.
Iterator yielding data from a Numpy array.
Inherits From: Iterator
, Sequence
View aliases
Compat aliases for migration
See
Migration guide for
more details.
`tf.compat.v1.keras.preprocessing.image.NumpyArrayIterator`
tf.keras.preprocessing.image.NumpyArrayIterator(
x,
y,
image_data_generator,
batch_size=32,
shuffle=False,
sample_weight=None,
seed=None,
data_format=None,
save_to_dir=None,
save_prefix='',
save_format='png',
subset=None,
ignore_class_split=False,
dtype=None
)
Args |
x
|
Numpy array of input data or tuple. If tuple, the second elements is
either another numpy array or a list of numpy arrays, each of which gets
passed through as an output without any modifications.
|
y
|
Numpy array of targets data.
|
image_data_generator
|
Instance of ImageDataGenerator to use for random
transformations and normalization.
|
batch_size
|
Integer, size of a batch.
|
shuffle
|
Boolean, whether to shuffle the data between epochs.
|
sample_weight
|
Numpy array of sample weights.
|
seed
|
Random seed for data shuffling.
|
data_format
|
String, one of channels_first , channels_last .
|
save_to_dir
|
Optional directory where to save the pictures being yielded,
in a viewable format. This is useful for visualizing the random
transformations being applied, for debugging purposes.
|
save_prefix
|
String prefix to use for saving sample images (if
save_to_dir is set).
|
save_format
|
Format to use for saving sample images (if save_to_dir is
set).
|
subset
|
Subset of data ("training" or "validation" ) if
validation_split is set in ImageDataGenerator.
|
ignore_class_split
|
Boolean (default: False), ignore difference
in number of classes in labels across train and validation
split (useful for non-classification tasks)
|
dtype
|
Dtype to use for the generated arrays.
|
Methods
next
View source
next()
For python 2.x.
on_epoch_end
View source
on_epoch_end()
Method called at the end of every epoch.
reset
View source
reset()
__getitem__
View source
__getitem__(
idx
)
Gets batch at position index
.
Args |
index
|
position of the batch in the Sequence.
|
__iter__
View source
__iter__()
Create a generator that iterate over the Sequence.
__len__
View source
__len__()
Number of batch in the Sequence.
Returns |
The number of batches in the Sequence.
|
Class Variables |
white_list_formats
|
('png', 'jpg', 'jpeg', 'bmp', 'ppm', 'tif', 'tiff')
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2023-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[],[],null,["# tf.keras.preprocessing.image.NumpyArrayIterator\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v2.9.0/keras/preprocessing/image.py#L559-L730) |\n\nIterator yielding data from a Numpy array.\n\nInherits From: [`Iterator`](../../../../tf/keras/preprocessing/image/Iterator), [`Sequence`](../../../../tf/keras/utils/Sequence)\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n\\`tf.compat.v1.keras.preprocessing.image.NumpyArrayIterator\\`\n\n\u003cbr /\u003e\n\n tf.keras.preprocessing.image.NumpyArrayIterator(\n x,\n y,\n image_data_generator,\n batch_size=32,\n shuffle=False,\n sample_weight=None,\n seed=None,\n data_format=None,\n save_to_dir=None,\n save_prefix='',\n save_format='png',\n subset=None,\n ignore_class_split=False,\n dtype=None\n )\n\n| **Deprecated:** [`tf.keras.preprocessing.image.NumpyArrayIterator`](../../../../tf/keras/preprocessing/image/NumpyArrayIterator) is not recommended for new code. Prefer loading images with [`tf.keras.utils.image_dataset_from_directory`](../../../../tf/keras/utils/image_dataset_from_directory) and transforming the output [`tf.data.Dataset`](../../../../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).\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `x` | Numpy array of input data or tuple. If tuple, the second elements is either another numpy array or a list of numpy arrays, each of which gets passed through as an output without any modifications. |\n| `y` | Numpy array of targets data. |\n| `image_data_generator` | Instance of `ImageDataGenerator` to use for random transformations and normalization. |\n| `batch_size` | Integer, size of a batch. |\n| `shuffle` | Boolean, whether to shuffle the data between epochs. |\n| `sample_weight` | Numpy array of sample weights. |\n| `seed` | Random seed for data shuffling. |\n| `data_format` | String, one of `channels_first`, `channels_last`. |\n| `save_to_dir` | Optional directory where to save the pictures being yielded, in a viewable format. This is useful for visualizing the random transformations being applied, for debugging purposes. |\n| `save_prefix` | String prefix to use for saving sample images (if `save_to_dir` is set). |\n| `save_format` | Format to use for saving sample images (if `save_to_dir` is set). |\n| `subset` | Subset of data (`\"training\"` or `\"validation\"`) if validation_split is set in ImageDataGenerator. |\n| `ignore_class_split` | Boolean (default: False), ignore difference in number of classes in labels across train and validation split (useful for non-classification tasks) |\n| `dtype` | Dtype to use for the generated arrays. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `next`\n\n[View source](https://github.com/keras-team/keras/tree/v2.9.0/keras/preprocessing/image.py#L150-L160) \n\n next()\n\nFor python 2.x.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The next batch. ||\n\n\u003cbr /\u003e\n\n### `on_epoch_end`\n\n[View source](https://github.com/keras-team/keras/tree/v2.9.0/keras/preprocessing/image.py#L115-L116) \n\n on_epoch_end()\n\nMethod called at the end of every epoch.\n\n### `reset`\n\n[View source](https://github.com/keras-team/keras/tree/v2.9.0/keras/preprocessing/image.py#L118-L119) \n\n reset()\n\n### `__getitem__`\n\n[View source](https://github.com/keras-team/keras/tree/v2.9.0/keras/preprocessing/image.py#L98-L110) \n\n __getitem__(\n idx\n )\n\nGets batch at position `index`.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|---------|----------------------------------------|\n| `index` | position of the batch in the Sequence. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| A batch ||\n\n\u003cbr /\u003e\n\n### `__iter__`\n\n[View source](https://github.com/keras-team/keras/tree/v2.9.0/keras/preprocessing/image.py#L142-L145) \n\n __iter__()\n\nCreate a generator that iterate over the Sequence.\n\n### `__len__`\n\n[View source](https://github.com/keras-team/keras/tree/v2.9.0/keras/preprocessing/image.py#L112-L113) \n\n __len__()\n\nNumber of batch in the Sequence.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| The number of batches in the Sequence. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Class Variables --------------- ||\n|--------------------|-------------------------------------------------------|\n| white_list_formats | `('png', 'jpg', 'jpeg', 'bmp', 'ppm', 'tif', 'tiff')` |\n\n\u003cbr /\u003e"]]