Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Conversation

@DOLARIK
Copy link

@DOLARIK DOLARIK commented Oct 8, 2020

Summary

This PR will help us apply custom transformations to the images at the time of data augmentation.

Introduces a new argument, list_of_custom_transformations, in ImageDataGenerator, wherein we can pass a list of all the custom transformations that we want to apply to the images.

For Example:

Consider the following custom transformations:

# Custom Transformation 1
def transformation_one(x):
  """
  transformation 1 code here.
  """
  return transformed_x

# Custom Transformation 2
def transformation_two(x):
  """
  transformation 2 code here.
  """
  return transformed_x

# Custom Transformation 3
class TransformationThree:
   ...

   def apply_transform(self, x):
      """
      transformation 3 code here.
      """
      return transformed_x

transformation_three = TransformationThree()

Now the above two custom transformations are to be passed to list_of_custom_transformations while instantiating ImageDataGenerator as shown below:

from keras_preprocessing.image import ImageDataGenerator

datagen = ImageDataGenerator(rotation_range = 90,
           zoom_range = 0.1, 
           shear_range = 0.3,
           width_shift_range=0.08,   
           height_shift_range=0.08,   
           vertical_flip=True,
           # custom transforms to be passed in list
           list_of_custom_transformations = [transformation_one, 
                                             transformation_two,
                                             transformation_three.apply_transform] 
)

And then the subsequent steps are as usual:

# train_gen
train_gen = datagen.flow(train_images, train_labels, batch_size = 32)

I believe this feature will help us during the research phase of a project for trying out new and custom transformations.

I have not added new tests for this feature yet. So, for you to test this out I have created this Colab Notebook. It includes demo transformations and visualizations.

This is my first PR and I am still figuring out the best practices for adding new tests and updating the docs. So, it would be very helpful if someone can share some useful links to articles on creating new unit tests.

This new feature has passed all the existing tests.

Also, I didn't understand the 3rd point in the PR Overview below. So, pls help me out with that too 😄

PR Overview

  • This PR requires new unit tests [y] (have not included yet)
  • This PR requires to update the documentation [y] (have not updated yet)
  • This PR is backwards compatible [?]
  • This PR changes the current API [y] (all API changes need to be approved by fchollet)

This will help us add a list of custom transformations on images
@Dref360
Copy link
Contributor

Dref360 commented Oct 9, 2020

Hello!
Thank you for your PR.
I am not sure if this is the right way to achieve what you want.

Recently, the TF team released Keras Preprocessing Layers which would apply transformations after the data augmentation (to add further transformations for example).

Is there a use-case where these layers are not working for you? If so, could you describe them so that we can fix that?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants