-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaug.py
62 lines (45 loc) · 2.11 KB
/
aug.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from typing import List
import albumentations as albu
from torchvision import transforms
def get_transforms(size: int, scope: str = 'geometric', crop='random'):
augs = {'strong': albu.Compose([albu.HorizontalFlip(),
albu.ShiftScaleRotate(shift_limit=0.0, scale_limit=0.2, rotate_limit=20, p=.4),
albu.ElasticTransform(),
albu.OpticalDistortion(),
albu.OneOf([
albu.CLAHE(clip_limit=2),
albu.IAASharpen(),
albu.IAAEmboss(),
albu.RandomBrightnessContrast(),
albu.RandomGamma()
], p=0.5),
albu.OneOf([
albu.RGBShift(),
albu.HueSaturationValue(),
], p=0.5),
]),
'weak': albu.Compose([albu.HorizontalFlip(),
]),
'geometric': albu.Compose([albu.HorizontalFlip(),
albu.VerticalFlip(),
albu.RandomRotate90(),
]),
'None': None
}
aug_fn = augs[scope]
crop_fn = {'random': albu.RandomCrop(size, size, always_apply=True),
'center': albu.CenterCrop(size, size, always_apply=True)}[crop]
pipeline = albu.Compose([aug_fn, crop_fn], additional_targets={'target': 'image'})
def process(a, b):
r = pipeline(image=a, target=b)
return r['image'], r['target']
return process
def get_normalize():
transform = transforms.Compose([
transforms.ToTensor()
])
def process(a, b):
image = transform(a).permute(1, 2, 0) - 0.5
target = transform(b).permute(1, 2, 0) - 0.5
return image, target
return process