Class ImageDataGenerator
Generate batches of tensor image data with real-time data augmentation. The data will be looped over (in batches).
Implements
Inherited Members
Namespace: Keras.PreProcessing.Image
Assembly: Keras.dll
Syntax
public class ImageDataGenerator : Base, IDisposable
Constructors
| Improve this Doc View SourceImageDataGenerator(Boolean, Boolean, Boolean, Boolean, Boolean, Single, Int32, Single, Single, Single[], Single, Single, Single, String, Single, Boolean, Boolean, Nullable<Single>, PyObject, String, Single, String)
Initializes a new instance of the ImageDataGenerator class.
Declaration
public ImageDataGenerator(bool featurewise_center = false, bool samplewise_center = false, bool featurewise_std_normalization = false, bool samplewise_std_normalization = false, bool zca_whitening = false, float zca_epsilon = 1E-06F, int rotation_range = 0, float width_shift_range = 0F, float height_shift_range = 0F, float[] brightness_range = null, float shear_range = 0F, float zoom_range = 0F, float channel_shift_range = 0F, string fill_mode = "nearest", float cval = 0F, bool horizontal_flip = false, bool vertical_flip = false, float? rescale = default(float? ), PyObject preprocessing_function = null, string data_format = "", float validation_split = 0F, string dtype = "")
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | featurewise_center | Boolean. Set input mean to 0 over the dataset, feature-wise. |
System.Boolean | samplewise_center | Boolean. Set each sample mean to 0. |
System.Boolean | featurewise_std_normalization | Boolean. Divide inputs by std of the dataset, feature-wise. |
System.Boolean | samplewise_std_normalization | Boolean. Divide each input by its std. |
System.Boolean | zca_whitening | Boolean. Apply ZCA whitening. |
System.Single | zca_epsilon | epsilon for ZCA whitening. Default is 1e-6. |
System.Int32 | rotation_range | Int. Degree range for random rotations. |
System.Single | width_shift_range | Float, 1-D array-like or int |
System.Single | height_shift_range | Float, 1-D array-like or int |
System.Single[] | brightness_range | Tuple or list of two floats. Range for picking a brightness shift value from. |
System.Single | shear_range | Float. Shear Intensity (Shear angle in counter-clockwise direction in degrees) |
System.Single | zoom_range | Float or [lower, upper]. Range for random zoom. If a float, [lower, upper] = [1-zoom_range, 1+zoom_range]. |
System.Single | channel_shift_range | Float. Range for random channel shifts. |
System.String | fill_mode | One of {"constant", "nearest", "reflect" or "wrap"}. Default is 'nearest'. Points outside the boundaries of the input are filled according to the given mode, 'constant'-> kkkkkkkk|abcd|kkkkkkkk (cval=k), 'nearest'-> aaaaaaaa|abcd|dddddddd, 'reflect'-> abcddcba|abcd|dcbaabcd, 'wrap'-> abcdabcd|abcd|abcdabcd |
System.Single | cval | Float or Int. Value used for points outside the boundaries when fill_mode = "constant". |
System.Boolean | horizontal_flip | Boolean. Randomly flip inputs horizontally. |
System.Boolean | vertical_flip | Boolean. Randomly flip inputs vertically. |
System.Nullable<System.Single> | rescale | rescaling factor. Defaults to None. If None or 0, no rescaling is applied, otherwise we multiply the data by the value provided (after applying all other transformations). |
Python.Runtime.PyObject | preprocessing_function | function that will be implied on each input. The function will run after the image is resized and augmented. The function should take one argument: one image (Numpy tensor with rank 3), and should output a Numpy tensor with the same shape. |
System.String | data_format | Image data format, either "channels_first" or "channels_last". "channels_last" mode means that the images should have shape (samples, height, width, channels), "channels_first" mode means that the images should have shape (samples, channels, height, width). It defaults to the image_data_format value found in your Keras config file at ~/.keras/keras.json. If you never set it, then it will be "channels_last". |
System.Single | validation_split | Float. Fraction of images reserved for validation (strictly between 0 and 1). |
System.String | dtype | Dtype to use for the generated arrays. |
Methods
| Improve this Doc View SourceApplyTransform(NDarray, Dictionary<String, Object>)
Applies the transform.
Declaration
public NDarray ApplyTransform(NDarray x, Dictionary<string, object> transform_parameters)
Parameters
Type | Name | Description |
---|---|---|
Numpy.NDarray | x | 3D tensor, single image. |
System.Collections.Generic.Dictionary<System.String, System.Object> | transform_parameters | Dictionary with string - parameter pairs describing the transformation. Currently, the following parameters from the dictionary are used: |
Returns
Type | Description |
---|---|
Numpy.NDarray | A transformed version of the input (same shape). |
Fit(NDarray, Boolean, Int32, Nullable<Int32>)
Fits the data generator to some sample data. This computes the internal data stats related to the data-dependent transformations, based on an array of sample data. Only required if featurewise_center or featurewise_std_normalization or zca_whitening are set to True.
Declaration
public void Fit(NDarray x, bool augment = false, int rounds = 1, int? seed = default(int? ))
Parameters
Type | Name | Description |
---|---|---|
Numpy.NDarray | x | The x. |
System.Boolean | augment | if set to |
System.Int32 | rounds | The rounds. |
System.Nullable<System.Int32> | seed | The seed. |
Flow(NDarray, NDarray, Int32, Boolean, NDarray, Nullable<Int32>, String, String, String, String)
Flows the specified x.
Declaration
public KerasIterator Flow(NDarray x, NDarray y = null, int batch_size = 32, bool shuffle = true, NDarray sample_weight = null, int? seed = default(int? ), string save_to_dir = "", string save_prefix = "", string save_format = "png", string subset = "")
Parameters
Type | Name | Description |
---|---|---|
Numpy.NDarray | x | Input data. Numpy array of rank 4 or a tuple. If tuple, the first element should contain the images and the second element another numpy array or a list of numpy arrays that gets passed to the output without any modifications. Can be used to feed the model miscellaneous data along with the images. In case of grayscale data, the channels axis of the image array should have value 1, in case of RGB data, it should have value 3, and in case of RGBA data, it should have value 4. |
Numpy.NDarray | y | Labels. |
System.Int32 | batch_size | Int (default: 32). |
System.Boolean | shuffle | Boolean (default: True). |
Numpy.NDarray | sample_weight | Sample weights. |
System.Nullable<System.Int32> | seed | Int (default: None). |
System.String | 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). |
System.String | save_prefix | Str (default: ''). Prefix to use for filenames of saved pictures (only relevant if save_to_dir is set). |
System.String | save_format | one of "png", "jpeg" (only relevant if save_to_dir is set). Default: "png". |
System.String | subset | Subset of data ("training" or "validation") if validation_split is set in ImageDataGenerator. |
Returns
Type | Description |
---|---|
KerasIterator | An Iterator yielding tuples of (x, y) where x is a numpy array of image data (in the case of a single image input) or a list of numpy arrays (in the case with additional inputs) and y is a numpy array of corresponding labels. If 'sample_weight' is not None, the yielded tuples are of the form (x, y, sample_weight). If y is None, only the numpy array x is returned. |
FlowFromDataframe(String, Tuple<Int32, Int32>, String, String[], String, Int32, Boolean, Nullable<Int32>, String, String, String, Boolean, String, String)
Flows from dataframe.
Declaration
public KerasIterator FlowFromDataframe(string directory, Tuple<int, int> target_size = null, string color_mode = "rgb", string[] classes = null, string class_mode = "categorical", int batch_size = 32, bool shuffle = true, int? seed = default(int? ), string save_to_dir = "", string save_prefix = "", string save_format = "png", bool follow_links = false, string subset = "", string interpolation = "nearest")
Parameters
Type | Name | Description |
---|---|---|
System.String | 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 for more details. |
System.Tuple<System.Int32, System.Int32> | target_size | Tuple of integers (height, width), default: (256, 256). The dimensions to which all images found will be resized. |
System.String | color_mode | One of "grayscale", "rgb", "rgba". Default: "rgb". Whether the images will be converted to have 1, 3, or 4 channels. |
System.String[] | 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. |
System.String | class_mode | One of "categorical", "binary", "sparse", "input", or None. Default: "categorical". Determines the type of label arrays that are returned: |
System.Int32 | batch_size | Size of the batches of data (default: 32). |
System.Boolean | shuffle | Whether to shuffle the data (default: True) If set to False, sorts the data in alphanumeric order. |
System.Nullable<System.Int32> | seed | Optional random seed for shuffling and transformations. |
System.String | 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). |
System.String | save_prefix | Str. Prefix to use for filenames of saved pictures (only relevant if save_to_dir is set). |
System.String | save_format | One of "png", "jpeg" (only relevant if save_to_dir is set). Default: "png". |
System.Boolean | follow_links | Whether to follow symlinks inside class subdirectories (default: False). |
System.String | subset | Subset of data ("training" or "validation") if validation_split is set in ImageDataGenerator. |
System.String | 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. |
Returns
Type | Description |
---|---|
KerasIterator | 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. |