Skip to content

Instantly share code, notes, and snippets.

@zhanwenchen
Forked from guillermogotre/unnormalize.py
Created July 2, 2025 18:27
Show Gist options
  • Save zhanwenchen/86c98df8a54cda047a43bd5c7fb88f66 to your computer and use it in GitHub Desktop.
Save zhanwenchen/86c98df8a54cda047a43bd5c7fb88f66 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