summaryrefslogtreecommitdiff
path: root/src/text_recognizer/datasets
diff options
context:
space:
mode:
authoraktersnurra <gustaf.rydholm@gmail.com>2020-11-18 20:56:19 +0100
committeraktersnurra <gustaf.rydholm@gmail.com>2020-11-18 20:56:19 +0100
commit527bb98b191d82b308de1585047e06056258d08d (patch)
treef33145dba398825871da3184a2735f6fb0b07268 /src/text_recognizer/datasets
parentf2cd16f340aa11afadb8fa90c29f85ca1b75a600 (diff)
Some minor changes.
Diffstat (limited to 'src/text_recognizer/datasets')
-rw-r--r--src/text_recognizer/datasets/transforms.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/text_recognizer/datasets/transforms.py b/src/text_recognizer/datasets/transforms.py
index d1ca127..1ec23dc 100644
--- a/src/text_recognizer/datasets/transforms.py
+++ b/src/text_recognizer/datasets/transforms.py
@@ -4,7 +4,7 @@ from PIL import Image
import torch
from torch import Tensor
import torch.nn.functional as F
-from torchvision.transforms import Compose, ToPILImage, ToTensor
+from torchvision.transforms import Compose, RandomAffine, ToTensor
from text_recognizer.datasets.util import EmnistMapper
@@ -66,9 +66,14 @@ class AddTokens:
return target
-class Whitening:
- """Whitening of Tensor, i.e. set mean to zero and std to one."""
+class ApplyContrast:
+ """Sets everything below a threshold to zero, i.e. increase contrast."""
+
+ def __init__(self, low: float = 0.0, high: float = 0.25) -> None:
+ self.low = low
+ self.high = high
def __call__(self, x: Tensor) -> Tensor:
- """Apply the whitening."""
- return (x - x.mean()) / x.std()
+ """Apply mask binary mask to input tensor."""
+ mask = x > np.random.RandomState().uniform(low=self.low, high=self.high)
+ return x * mask