Skip to content

Instantly share code, notes, and snippets.

@guillermogotre
Created March 20, 2022 15:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save guillermogotre/844024ac37d35c8a00a6133887cbd18b to your computer and use it in GitHub Desktop.
Save guillermogotre/844024ac37d35c8a00a6133887cbd18b to your computer and use it in GitHub Desktop.
PyTorch Torchvision UnNormalize (reverse Normalize)
import torchvision
class UnNormalize(torchvision.transforms.Normalize):
def __init__(self,mean,std,*args,**kwargs):
new_mean = [-m/s for m,s in zip(mean,std)]
new_std = [1/s for s in std]
super().__init__(new_mean, new_std, *args, **kwargs)
# imagenet_norm = dict(mean=[0.485, 0.456, 0.406],std=[0.229, 0.224, 0.225])
# UnNormalize(**imagenet_norm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment