Created
March 12, 2023 10:25
-
-
Save EckoTan0804/47a6565fa637af598e833a385615b312 to your computer and use it in GitHub Desktop.
Unnormalize normalized PyTorch tensor
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
class UnNormalize(object): | |
def __init__(self, mean, std): | |
self.mean = mean | |
self.std = std | |
def __call__(self, tensor): | |
""" | |
Args: | |
tensor (Tensor): Tensor image of size (C, H, W) to be normalized. | |
Returns: | |
Tensor: Normalized image. | |
""" | |
for t, m, s in zip(tensor, self.mean, self.std): | |
t.mul_(s).add_(m) | |
# The normalize code -> t.sub_(m).div_(s) | |
return tensor |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment