summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhang <zch921005@126.com>2023-03-01 21:59:48 +0800
committerzhang <zch921005@126.com>2023-03-01 21:59:48 +0800
commit28d23fcdb0ad185a77c74ff38f245cc9c3905071 (patch)
tree2d70373cf45a57f5d32009ee1a472ef433254ac1
parent5eef16295b5506370591ec3a41bf114e52addf67 (diff)
unnorm
-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