diff options
author | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2022-09-27 01:44:49 +0200 |
---|---|---|
committer | Gustaf Rydholm <gustaf.rydholm@gmail.com> | 2022-09-27 01:44:49 +0200 |
commit | 9b8e14d89f0ef2508ed11f994f73af624155fe1d (patch) | |
tree | 10d9c138f4449646c8b5c0f95003ba86b831d04d /text_recognizer/data/stems/image.py | |
parent | 63376b1c2da81c23ad5239f908b640cd42a514c7 (diff) |
Update data modules
Diffstat (limited to 'text_recognizer/data/stems/image.py')
-rw-r--r-- | text_recognizer/data/stems/image.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/text_recognizer/data/stems/image.py b/text_recognizer/data/stems/image.py new file mode 100644 index 0000000..f04b3a0 --- /dev/null +++ b/text_recognizer/data/stems/image.py @@ -0,0 +1,18 @@ +from PIL import Image +import torch +from torch import Tensor +import torchvision.transforms as T + + +class ImageStem: + def __init__(self) -> None: + self.pil_transform = T.Compose([]) + self.pil_to_tensor = T.ToTensor() + self.torch_transform = torch.nn.Sequential() + + def __call__(self, img: Image) -> Tensor: + img = self.pil_transform(img) + img = self.pil_to_tensor(img) + with torch.no_grad(): + img = self.torch_transform(img) + return img |