Created
March 20, 2022 15:44
-
-
Save guillermogotre/844024ac37d35c8a00a6133887cbd18b to your computer and use it in GitHub Desktop.
PyTorch Torchvision UnNormalize (reverse Normalize)
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 | |
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