Created
August 8, 2019 18:34
-
-
Save Lexie88rus/b6e66497a1b4b14aa01cc41e126a7c20 to your computer and use it in GitHub Desktop.
Pipelining augmentations with Albumentations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Compose a complex augmentation pipeline | |
augmentation_pipeline = A.Compose( | |
[ | |
A.HorizontalFlip(p = 0.5), # apply horizontal flip to 50% of images | |
A.OneOf( | |
[ | |
# apply one of transforms to 50% of images | |
A.RandomContrast(), # apply random contrast | |
A.RandomGamma(), # apply random gamma | |
A.RandomBrightness(), # apply random brightness | |
], | |
p = 0.5 | |
), | |
A.OneOf( | |
[ | |
# apply one of transforms to 50% images | |
A.ElasticTransform( | |
alpha = 120, | |
sigma = 120 * 0.05, | |
alpha_affine = 120 * 0.03 | |
), | |
A.GridDistortion(), | |
A.OpticalDistortion( | |
distort_limit = 2, | |
shift_limit = 0.5 | |
), | |
], | |
p = 0.5 | |
) | |
], | |
p = 1 | |
) | |
# Apply pipeline to sample image | |
images_aug = np.array([augmentation_pipeline(image = image)['image'] for _ in range(16)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment