[95f789]: / src / augmentation.py

Download this file

73 lines (63 with data), 2.0 kB

 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from albumentations import *
import itertools
def train_aug(image_size, normalization=True):
if normalization:
return Compose([
Resize(*image_size),
# Rotate(10),
HorizontalFlip(),
OneOf([
ElasticTransform(alpha=120, sigma=120 * 0.05, alpha_affine=120 * 0.03),
GridDistortion(),
OpticalDistortion(distort_limit=2, shift_limit=0.5),
], p=0.3),
ShiftScaleRotate(shift_limit=0.05, scale_limit=0.1, rotate_limit=10),
# ChannelDropout(),
Normalize()
], p=1)
else:
return Compose([
Resize(*image_size),
# Rotate(10),
HorizontalFlip(),
OneOf([
ElasticTransform(alpha=120, sigma=120 * 0.05, alpha_affine=120 * 0.03),
GridDistortion(),
OpticalDistortion(distort_limit=2, shift_limit=0.5),
], p=0.3),
ShiftScaleRotate(shift_limit=0.05, scale_limit=0.1, rotate_limit=10),
], p=1)
def valid_aug(image_size, normalization=True):
if normalization:
return Compose([
Resize(*image_size),
Normalize()
], p=1)
else:
return Compose([
Resize(*image_size),
], p=1)
def test_tta(image_size, normalization=True):
if normalization:
test_dict = {
'normal': Compose([
Resize(*image_size),
Normalize()
], p=1),
'hflip': Compose([
Resize(*image_size),
HorizontalFlip(p=1),
Normalize()
], p=1),
}
else:
test_dict = {
'normal': Compose([
Resize(*image_size),
], p=1),
'hflip': Compose([
Resize(*image_size),
HorizontalFlip(p=1),
], p=1),
}
return test_dict