Skip to content

Instantly share code, notes, and snippets.

@aunsid
Created September 14, 2020 15:20
Show Gist options
  • Save aunsid/538981d369191fb327b9205fe086c4b7 to your computer and use it in GitHub Desktop.
Save aunsid/538981d369191fb327b9205fe086c4b7 to your computer and use it in GitHub Desktop.
Random Gamma Correction Data Augmentation Pytorch
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