import os

# I assume you have a way of loading your 
# images from the filesystem, and they come 
# out of `images` (an iterator)

AUG_SAVE_DIR = 'data/augmented'

# create directory of not present already
if not os.path.isdir(AUG_SAVE_DIR):

# This will create augmentation ids for the same image
# example: '00', '01', '02', ..., '08', '09' for
#          - NUM_AUG_REPEAT = 10
aug_id = lambda x: str(x).zfill(len(str(NUM_AUG_REPEAT)))

for image in images:
    for i in range(NUM_AUG_REPEAT):
        data = {'image': image}
        augmented = augmentation(**data)
        # I assume you have a function: save_image(image_path, image)
        # You need to write this function with 
        # whatever logic necessary. (Hint: use imageio or PIL.Image)
        image_filename = f'image_name_{aug_id(i)}.png'
        save_image(os.path.join(AUG_SAVE_DIR, image_filename), augmented['image'])
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter