tf.keras.preprocessing.image.DirectoryIterator
Stay organized with collections
Save and categorize content based on your preferences.
Iterator capable of reading images from a directory on disk.
Inherits From: Iterator
, PyDataset
tf.keras.preprocessing.image.DirectoryIterator(
directory,
image_data_generator,
target_size=(256, 256),
color_mode='rgb',
classes=None,
class_mode='categorical',
batch_size=32,
shuffle=True,
seed=None,
data_format=None,
save_to_dir=None,
save_prefix='',
save_format='png',
follow_links=False,
subset=None,
interpolation='nearest',
keep_aspect_ratio=False,
dtype=None
)
DEPRECATED.
Attributes |
filepaths
|
List of absolute paths to image files.
|
labels
|
Class labels of every observation.
|
max_queue_size
|
|
num_batches
|
Number of batches in the PyDataset.
|
sample_weight
|
|
use_multiprocessing
|
|
workers
|
|
Methods
on_epoch_end
View source
on_epoch_end()
Method called at the end of every epoch.
reset
View source
reset()
set_processing_attrs
View source
set_processing_attrs(
image_data_generator,
target_size,
color_mode,
data_format,
save_to_dir,
save_prefix,
save_format,
subset,
interpolation,
keep_aspect_ratio
)
Sets attributes to use later for processing files into a batch.
Args |
image_data_generator
|
Instance of ImageDataGenerator
to use for random transformations and normalization.
|
target_size
|
tuple of integers, dimensions to resize input images
to.
|
color_mode
|
One of "rgb" , "rgba" , "grayscale" .
Color mode to read images.
|
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.
|
interpolation
|
Interpolation method used to resample the image if
the target size is different from that of the loaded image.
Supported methods are "nearest", "bilinear", and "bicubic". If
PIL version 1.1.3 or newer is installed, "lanczos" is also
supported. If PIL version 3.4.0 or newer is installed, "box" and
"hamming" are also supported. By default, "nearest" is used.
|
keep_aspect_ratio
|
Boolean, whether to resize images to a target
size without aspect ratio distortion. The image is cropped in
the center with target aspect ratio before resizing.
|
__getitem__
View source
__getitem__(
idx
)
Gets batch at position index
.
Args |
index
|
position of the batch in the PyDataset.
|
__iter__
View source
__iter__()
__len__
View source
__len__()
Class Variables |
allowed_class_modes
|
{
'binary',
'categorical',
'input',
'sparse',
None
}
|
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 2024-06-07 UTC.
[null,null,["Last updated 2024-06-07 UTC."],[],[],null,["# tf.keras.preprocessing.image.DirectoryIterator\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/legacy/preprocessing/image.py#L392-L512) |\n\nIterator capable of reading images from a directory on disk.\n\nInherits From: [`Iterator`](../../../../tf/keras/preprocessing/image/Iterator), [`PyDataset`](../../../../tf/keras/utils/PyDataset) \n\n tf.keras.preprocessing.image.DirectoryIterator(\n directory,\n image_data_generator,\n target_size=(256, 256),\n color_mode='rgb',\n classes=None,\n class_mode='categorical',\n batch_size=32,\n shuffle=True,\n seed=None,\n data_format=None,\n save_to_dir=None,\n save_prefix='',\n save_format='png',\n follow_links=False,\n subset=None,\n interpolation='nearest',\n keep_aspect_ratio=False,\n dtype=None\n )\n\nDEPRECATED.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|-----------------------|----------------------------------------|\n| `filepaths` | List of absolute paths to image files. |\n| `labels` | Class labels of every observation. |\n| `max_queue_size` | \u003cbr /\u003e \u003cbr /\u003e |\n| `num_batches` | Number of batches in the PyDataset. |\n| `sample_weight` | \u003cbr /\u003e \u003cbr /\u003e |\n| `use_multiprocessing` | \u003cbr /\u003e \u003cbr /\u003e |\n| `workers` | \u003cbr /\u003e \u003cbr /\u003e |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `on_epoch_end`\n\n[View source](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/legacy/preprocessing/image.py#L73-L74) \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/v3.3.3/keras/src/legacy/preprocessing/image.py#L76-L77) \n\n reset()\n\n### `set_processing_attrs`\n\n[View source](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/legacy/preprocessing/image.py#L210-L296) \n\n set_processing_attrs(\n image_data_generator,\n target_size,\n color_mode,\n data_format,\n save_to_dir,\n save_prefix,\n save_format,\n subset,\n interpolation,\n keep_aspect_ratio\n )\n\nSets attributes to use later for processing files into a batch.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `image_data_generator` | Instance of `ImageDataGenerator` to use for random transformations and normalization. |\n| `target_size` | tuple of integers, dimensions to resize input images to. |\n| `color_mode` | One of `\"rgb\"`, `\"rgba\"`, `\"grayscale\"`. Color mode to read images. |\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| `interpolation` | Interpolation method used to resample the image if the target size is different from that of the loaded image. Supported methods are \"nearest\", \"bilinear\", and \"bicubic\". If PIL version 1.1.3 or newer is installed, \"lanczos\" is also supported. If PIL version 3.4.0 or newer is installed, \"box\" and \"hamming\" are also supported. By default, \"nearest\" is used. |\n| `keep_aspect_ratio` | Boolean, whether to resize images to a target size without aspect ratio distortion. The image is cropped in the center with target aspect ratio before resizing. |\n\n\u003cbr /\u003e\n\n### `__getitem__`\n\n[View source](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/legacy/preprocessing/image.py#L53-L68) \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 PyDataset. |\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/v3.3.3/keras/src/legacy/preprocessing/image.py#L102-L105) \n\n __iter__()\n\n### `__len__`\n\n[View source](https://github.com/keras-team/keras/tree/v3.3.3/keras/src/legacy/preprocessing/image.py#L70-L71) \n\n __len__()\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Class Variables --------------- ||\n|---------------------|--------------------------------------------------------------------|\n| allowed_class_modes | \u003cbr /\u003e { 'binary', 'categorical', 'input', 'sparse', None } \u003cbr /\u003e |\n| white_list_formats | `('png', 'jpg', 'jpeg', 'bmp', 'ppm', 'tif', 'tiff')` |\n\n\u003cbr /\u003e"]]