-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaugmentation.py
33 lines (26 loc) · 888 Bytes
/
augmentation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""Augmentation Code."""
import torchvision.transforms as T
from randaugment import RandAugment
class Augmenter:
"""Image Augmenter."""
def __init__(self, policy):
"""Get a policy."""
# for model evaluation
if policy == 0:
self.transform = lambda x: x
# weak augmentation
elif policy == 1:
self.transform = T.Compose([
T.RandomHorizontalFlip(p=0.5),
T.RandomCrop(32, padding=4, padding_mode='reflect')
])
# strong augmentation
elif policy == 2:
self.transform = T.Compose([
T.RandomHorizontalFlip(p=0.5),
T.RandomCrop(32, padding=4, padding_mode='reflect'),
RandAugment(n=2, m=10)
])
def __call__(self, image):
"""Augmenter."""
return self.transform(image)