Skip to content

Commit

Permalink
[keras/preprocessing/image.py] Consistent indent of 2 for `flow_from_…
Browse files Browse the repository at this point in the history
…directory` docstring ; `flow_from_directory` defaults-to in docstring
  • Loading branch information
SamuelMarks committed May 4, 2023
1 parent af5d96a commit 44c0b83
Showing 1 changed file with 63 additions and 62 deletions.
125 changes: 63 additions & 62 deletions keras/preprocessing/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,70 +1580,71 @@ def flow_from_directory(
"""Takes the path to a directory & generates batches of augmented data.
Args:
directory: string, path to the target directory. It should contain
one subdirectory per class. Any PNG, JPG, BMP, PPM or TIF images
inside each of the subdirectories directory tree will be included
in the generator. See [this script](
https://gist.github.com/fchollet/0830affa1f7f19fd47b06d4cf89ed44d)
for more details.
target_size: Tuple of integers `(height, width)`. The dimensions to
which all images found will be resized. Defaults to `(256,256)`.
color_mode: One of "grayscale", "rgb", "rgba". Default: "rgb".
Whether the images will be converted to have 1, 3, or 4 channels.
classes: Optional list of class subdirectories (e.g. `['dogs',
'cats']`). Default: None. If not provided, the list of classes
will be automatically inferred from the subdirectory
names/structure under `directory`, where each subdirectory will be
treated as a different class (and the order of the classes, which
will map to the label indices, will be alphanumeric). The
dictionary containing the mapping from class names to class
indices can be obtained via the attribute `class_indices`.
class_mode: One of "categorical", "binary", "sparse",
"input", or None. Default: "categorical".
Determines the type of label arrays that are returned:
- "categorical" will be 2D one-hot encoded labels,
- "binary" will be 1D binary labels,
"sparse" will be 1D integer labels,
- "input" will be images identical
to input images (mainly used to work with autoencoders).
- If None, no labels are returned
(the generator will only yield batches of image data,
which is useful to use with `model.predict_generator()`).
Please note that in case of class_mode None,
the data still needs to reside in a subdirectory
of `directory` for it to work correctly.
batch_size: Size of the batches of data (default: 32).
shuffle: Whether to shuffle the data (default: True) If set to
False, sorts the data in alphanumeric order.
seed: Optional random seed for shuffling and transformations.
save_to_dir: None or str (default: None). This allows you to
optionally specify a directory to which to save the augmented
pictures being generated (useful for visualizing what you are
doing).
save_prefix: Str. Prefix to use for filenames of saved pictures
(only relevant if `save_to_dir` is set).
save_format: one of "png", "jpeg", "bmp", "pdf", "ppm", "gif",
"tif", "jpg" (only relevant if `save_to_dir` is set). Default:
"png".
follow_links: Whether to follow symlinks inside
class subdirectories (default: False).
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.
directory: string, path to the target directory. It should contain
one subdirectory per class. Any PNG, JPG, BMP, PPM or TIF images
inside each of the subdirectories directory tree will be included
in the generator. See [this script](
https://gist.github.com/fchollet/0830affa1f7f19fd47b06d4cf89ed44d)
for more details.
target_size: Tuple of integers `(height, width)`. The dimensions to
which all images found will be resized. Defaults to `(256,256)`.
color_mode: One of "grayscale", "rgb", "rgba". Default: "rgb".
Whether the images will be converted to have 1, 3, or 4 channels.
classes: Optional list of class subdirectories (e.g. `['dogs',
'cats']`). Default: None. If not provided, the list of classes
will be automatically inferred from the subdirectory
names/structure under `directory`, where each subdirectory will be
treated as a different class (and the order of the classes, which
will map to the label indices, will be alphanumeric). The
dictionary containing the mapping from class names to class
indices can be obtained via the attribute `class_indices`.
class_mode: One of "categorical", "binary", "sparse",
"input", or None.
Determines the type of label arrays that are returned:
- "categorical" will be 2D one-hot encoded labels,
- "binary" will be 1D binary labels,
- "sparse" will be 1D integer labels,
- "input" will be images identical
to input images (mainly used to work with autoencoders).
- If None, no labels are returned
(the generator will only yield batches of image data,
which is useful to use with `model.predict_generator()`).
Please note that in case of class_mode None,
the data still needs to reside in a subdirectory
of `directory` for it to work correctly.
Defaults to "categorical".
batch_size: Size of the batches of data. Defaults to `32`.
shuffle: Whether to shuffle the data If `False`, sorts the
data in alphanumeric order. Defaults to `True`.
seed: Optional random seed for shuffling and transformations.
save_to_dir: None or str (default: None). This allows you to
optionally specify a directory to which to save the augmented
pictures being generated (useful for visualizing what you are
doing).
save_prefix: Str. Prefix to use for filenames of saved pictures
(only relevant if `save_to_dir` is set).
save_format: one of "png", "jpeg", "bmp", "pdf", "ppm", "gif",
"tif", "jpg" (only relevant if `save_to_dir` is set).
Defaults to "png".
follow_links: Whether to follow symlinks inside
class subdirectories. Defaults to `False`.
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. Defaults to `"nearest"`.
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.
Returns:
A `DirectoryIterator` yielding tuples of `(x, y)`
where `x` is a numpy array containing a batch
of images with shape `(batch_size, *target_size, channels)`
and `y` is a numpy array of corresponding labels.
A `DirectoryIterator` yielding tuples of `(x, y)`
where `x` is a numpy array containing a batch
of images with shape `(batch_size, *target_size, channels)`
and `y` is a numpy array of corresponding labels.
"""
return DirectoryIterator(
directory,
Expand Down

0 comments on commit 44c0b83

Please sign in to comment.