summaryrefslogtreecommitdiff
path: root/src/text_recognizer/datasets
diff options
context:
space:
mode:
authoraktersnurra <gustaf.rydholm@gmail.com>2020-11-16 20:26:32 +0100
committeraktersnurra <gustaf.rydholm@gmail.com>2020-11-16 20:26:32 +0100
commitf2cd16f340aa11afadb8fa90c29f85ca1b75a600 (patch)
tree8a7b32a9b2662b3b3bcec1119a9e6a25bb599cb9 /src/text_recognizer/datasets
parent75909723fa2b1f6245d5c5422e4f2e88b8a26052 (diff)
Added a whitening transform.
Diffstat (limited to 'src/text_recognizer/datasets')
-rw-r--r--src/text_recognizer/datasets/transforms.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/text_recognizer/datasets/transforms.py b/src/text_recognizer/datasets/transforms.py
index 1105f23..d1ca127 100644
--- a/src/text_recognizer/datasets/transforms.py
+++ b/src/text_recognizer/datasets/transforms.py
@@ -64,3 +64,11 @@ class AddTokens:
target = torch.cat([sos, target], dim=0)
return target
+
+
+class Whitening:
+ """Whitening of Tensor, i.e. set mean to zero and std to one."""
+
+ def __call__(self, x: Tensor) -> Tensor:
+ """Apply the whitening."""
+ return (x - x.mean()) / x.std()