summaryrefslogtreecommitdiff
path: root/dl/tutorials
diff options
context:
space:
mode:
Diffstat (limited to 'dl/tutorials')
-rw-r--r--dl/tutorials/utils.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/dl/tutorials/utils.py b/dl/tutorials/utils.py
index 8368e94..89c010f 100644
--- a/dl/tutorials/utils.py
+++ b/dl/tutorials/utils.py
@@ -16,3 +16,21 @@ def get_mean_and_std(dataset):
mean.div_(len(dataset))
std.div_(len(dataset))
return mean, std
+
+
+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