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

Extending Cutout with a probability of when it is applied #14

Open
aisosalo opened this issue Jul 8, 2021 · 3 comments
Open

Extending Cutout with a probability of when it is applied #14

aisosalo opened this issue Jul 8, 2021 · 3 comments

Comments

@aisosalo
Copy link

aisosalo commented Jul 8, 2021

How about adding also a probability to vary when Cutout is applied? For example something like this:

class Cutout(object):
    """Randomly mask out one or more patches from an image.
    Args:
        n_holes (int): Number of patches to cut out of each image.
        length (int): The length (in pixels) of each square patch.
        p1 (float): Probability of applying CutOut (default value 1, always applied).
    """
    def __init__(self, n_holes, length, p1=1.0):
        self.n_holes = n_holes
        self.length = length
        self.p1 = p1
		
    def __call__(self, img):
        """
        Args:
            img (Tensor): Tensor image of size (C, H, W).
        Returns:
            Tensor: Image with n_holes of dimension length x length cut out of it.
        """
        if torch.rand(1) > p1:  #np.random.rand(1) > p1:  
            return img
            
            # [...]
            
            return img

So, when np.random.rand(1) is larger than p1 the input image is returned unchanged (most of the time if p1 is small), if I got it right.

@TDeVries
Copy link
Collaborator

TDeVries commented Jul 9, 2021

Yup, this is definitely a possibility!

@gwtaylor
Copy link

gwtaylor commented Jul 9, 2021

If you do an experiment, let us know your results!

@aisosalo
Copy link
Author

aisosalo commented Jul 9, 2021

Would you be willing to update your repository with the added functionality in the meantime?

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

No branches or pull requests

3 participants