Created
September 14, 2020 15:20
-
-
Save aunsid/538981d369191fb327b9205fe086c4b7 to your computer and use it in GitHub Desktop.
Random Gamma Correction Data Augmentation Pytorch
This file contains 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
import torchvision.transforms.functional as TF | |
class RandomGammaCorrection(object): | |
""" | |
Apply Gamma Correction to the images | |
""" | |
def __init__(self, gamma = None): | |
self.gamma = gamma | |
def __call__(self,image): | |
if self.gamma == None: | |
# more chances of selecting 0 (original image) | |
gammas = [0,0,0,0.5,1,1.5] | |
self.gamma = random.choice(gammas) | |
print(self.gamma) | |
if self.gamma == 0: | |
return image | |
else: | |
return TF.adjust_gamma(image, self.gamma, gain=1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment