How to change pre_processing function execution order for ImageDataGenerator at Keras?

953 views Asked by At

I am using Keras's "ImageDataGenerator" class for data augmentation. Since the image has the bounding box of the relevant object, I want to crop the image to the relevant part before augmenting it. The class has an argument named "preprocessing_function" among its arguments and allows us to implement the desired function after augmentation and resizing. I am asking for this to happen the opposite. First, let the function run, then the augmentation takes place. How can I implement that to the code?

tf.keras.preprocessing.image.ImageDataGenerator(
    featurewise_center=False,
    samplewise_center=False,
    featurewise_std_normalization=False,
    samplewise_std_normalization=False,
    zca_whitening=False,
    zca_epsilon=1e-06,
    rotation_range=0,
    width_shift_range=0.0,
    height_shift_range=0.0,
    brightness_range=None,
    shear_range=0.0,
    zoom_range=0.0,
    channel_shift_range=0.0,
    fill_mode="nearest",
    cval=0.0,
    horizontal_flip=False,
    vertical_flip=False,
    rescale=None,
    preprocessing_function=None,
    data_format=None,
    validation_split=0.0,
    dtype=None,
)

preprocessing_function: a function that will be applied to 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.

1

There are 1 answers

0
Omer Sarioglu On BEST ANSWER

Keras team members said that the ImageDataGenerator class is legacy. They suggest me to use transformation layers. They can be used anytime while training.

Example usage of transformation layers: Keras Transformation layers example page

Github Issue (Closed): GitHub Issues