Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to seed augmentations #119

Open
ierezell opened this issue Sep 14, 2021 · 3 comments
Open

Is it possible to seed augmentations #119

ierezell opened this issue Sep 14, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@ierezell
Copy link

🚀 Feature

Checked the code and it doesn't seem possible to seed the augmenters.

Motivation

To reproduce the same augmented test sets.
Also to (deterministically) augment small test sets.

Pitch

Adding the possibility to seed augmenters like My_Augmenter(**my_params, seed=42) which would make reproducible augmentations. Not always the same for all the batch but always in the same order in a reproducible manner.

Alternatives

Don't use augmentation in the test set.

Additional context

I'm working with text, and I would like to augment a test set but the idea also apply to images and audio.

Thanks in advance and thanks a lot for this nice library !

@zpapakipos
Copy link
Contributor

Hi @ierezell, thanks for this request! We currently have a seed arg for some augmentations that include random sampling within them (e.g. change_case in text https://github.com/facebookresearch/AugLy/blob/main/augly/text/functional.py#L65 or perspective_transform in image https://github.com/facebookresearch/AugLy/blob/main/augly/image/functional.py#L1719), but it's true that this is missing for some (e.g. insert_punctuation_chars in text https://github.com/facebookresearch/AugLy/blob/main/augly/text/functional.py#L144).

I will add this to our list of tasks to do soon, to add seed args to all augmentations that involve random sampling which don't already have it.

@zpapakipos zpapakipos added the enhancement New feature or request label Sep 23, 2021
@sciencecw
Copy link

It is good that change_case has seed argument, but the current implementation means that without specifying the seed, it keeps generating the same result

@javiabellan
Copy link

javiabellan commented Feb 9, 2024

AugLy is cool, however many transformations are not random:

Here is a code snippet to make any transfomation random, (even with the random distributions you preffer):

import numpy as np
import augly.image as imaugs
    
def random_uniform(min,max):
    return lambda: np.random.uniform(min, max)
    
def random_normal(mean,std):
    return lambda: np.random.normal(mean, std)

def randomize(fn_2_randomize, **kwargs):
    def randomized_fn(img_pil):
        # 1) Compute random_params into fixed_params:
        fixed_args = {}
        for key_paramName, value_randomFn in kwargs.items():
            fixed_args[key_paramName] = value_randomFn()
        # 2) Call PIL function with fixed_params
        return fn_2_randomize(img_pil, **fixed_args)
    return randomized_fn

random_overlay_text = randomize(imaugs.overlay_text,
                                x_pos=random_uniform(0,0.5),
                                y_pos=random_uniform(0,0.9))

# Now you can call it :)
random_overlay_text(img)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants