Diff of /src/augmentation.py [000000] .. [95f789]

Switch to unified view

a b/src/augmentation.py
1
from albumentations import *
2
3
import itertools
4
5
6
def train_aug(image_size, normalization=True):
7
    if normalization:
8
        return Compose([
9
            Resize(*image_size),
10
            # Rotate(10),
11
            HorizontalFlip(),
12
            OneOf([
13
                ElasticTransform(alpha=120, sigma=120 * 0.05, alpha_affine=120 * 0.03),
14
                GridDistortion(),
15
                OpticalDistortion(distort_limit=2, shift_limit=0.5),
16
            ], p=0.3),
17
            ShiftScaleRotate(shift_limit=0.05, scale_limit=0.1, rotate_limit=10),
18
            # ChannelDropout(),
19
            Normalize()
20
        ], p=1)
21
    else:
22
        return Compose([
23
            Resize(*image_size),
24
            # Rotate(10),
25
            HorizontalFlip(),
26
            OneOf([
27
                ElasticTransform(alpha=120, sigma=120 * 0.05, alpha_affine=120 * 0.03),
28
                GridDistortion(),
29
                OpticalDistortion(distort_limit=2, shift_limit=0.5),
30
            ], p=0.3),
31
            ShiftScaleRotate(shift_limit=0.05, scale_limit=0.1, rotate_limit=10),
32
        ], p=1)
33
34
35
def valid_aug(image_size, normalization=True):
36
    if normalization:
37
        return Compose([
38
            Resize(*image_size),
39
            Normalize()
40
        ], p=1)
41
    else:
42
        return Compose([
43
            Resize(*image_size),
44
        ], p=1)
45
46
47
def test_tta(image_size, normalization=True):
48
    if normalization:
49
        test_dict = {
50
            'normal': Compose([
51
                Resize(*image_size),
52
                Normalize()
53
            ], p=1),
54
55
            'hflip': Compose([
56
                Resize(*image_size),
57
                HorizontalFlip(p=1),
58
                Normalize()
59
            ], p=1),
60
        }
61
    else:
62
        test_dict = {
63
            'normal': Compose([
64
                Resize(*image_size),
65
            ], p=1),
66
67
            'hflip': Compose([
68
                Resize(*image_size),
69
                HorizontalFlip(p=1),
70
            ], p=1),
71
        }
72
73
    return test_dict