Skip to content

Instantly share code, notes, and snippets.

@tomahim
Last active March 4, 2018 21:33
Show Gist options
  • Save tomahim/d00013aa061e8a130d01c9b4178e0cab to your computer and use it in GitHub Desktop.
Save tomahim/d00013aa061e8a130d01c9b4178e0cab to your computer and use it in GitHub Desktop.
Apply random transformations
# dictionary of the transformations functions we defined earlier
available_transformations = {
'rotate': random_rotation,
'noise': random_noise,
'horizontal_flip': horizontal_flip
}
# random num of transformations to apply
num_transformations_to_apply = random.randint(1, len(available_transformations))
num_transformations = 0
transformed_image = None
while num_transformations <= num_transformations_to_apply:
# choose a random transformation to apply for a single image
key = random.choice(list(available_transformations))
transformed_image = available_transformations[key](image_to_transform)
num_transformations += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment