From 7cfe973e8202d0fea80766570d8d81609a856a1e Mon Sep 17 00:00:00 2001 From: Divyanshu Gupta Date: Sun, 4 Oct 2020 17:04:06 +0530 Subject: [PATCH] Add custom transformations This will help us add a list of custom transformations on images --- keras_preprocessing/image/image_data_generator.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/keras_preprocessing/image/image_data_generator.py b/keras_preprocessing/image/image_data_generator.py index 77d88147..21472857 100644 --- a/keras_preprocessing/image/image_data_generator.py +++ b/keras_preprocessing/image/image_data_generator.py @@ -102,6 +102,7 @@ class ImageDataGenerator(object): (strictly between 0 and 1). interpolation_order: int, order to use for the spline interpolation. Higher is slower. + list_of_custom_transformations: list, list of transformation functions dtype: Dtype to use for the generated arrays. # Examples @@ -274,6 +275,7 @@ def __init__(self, data_format='channels_last', validation_split=0.0, interpolation_order=1, + list_of_custom_transformations=None, dtype='float32'): self.featurewise_center = featurewise_center @@ -296,6 +298,7 @@ def __init__(self, self.preprocessing_function = preprocessing_function self.dtype = dtype self.interpolation_order = interpolation_order + self.list_of_custom_transformations = list_of_custom_transformations if data_format not in {'channels_last', 'channels_first'}: raise ValueError( @@ -892,6 +895,11 @@ def apply_transform(self, x, transform_parameters): if transform_parameters.get('brightness') is not None: x = apply_brightness_shift(x, transform_parameters['brightness']) + # Custom Transformations + if self.list_of_custom_transformations: + for transformation in self.list_of_custom_transformations: + x = transformation(x) + return x def random_transform(self, x, seed=None):