-
Notifications
You must be signed in to change notification settings - Fork 2
/
transform.py
61 lines (56 loc) · 2.34 KB
/
transform.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
57
58
59
60
from torchvision import transforms
from utils import NonUniformScaling
def load_train_transform_img(config):
return transforms.Compose(
[
transforms.Resize((config.img_size, config.img_size), interpolation=config.img_interpolation),
transforms.RandomCrop(config.img_size, padding=32, fill=0, padding_mode='constant'),
transforms.RandomHorizontalFlip(p=config.flip_p),
transforms.RandomApply([
NonUniformScaling(scale_x_range=config.scale_x, scale_y_range=config.scale_y),
transforms.RandomAffine(
degrees=config.degrees,
translate=config.translate,
scale=config.scale,
shear=config.shear
),
], p=config.apply_p),
transforms.ToTensor(),
transforms.Normalize([0.5], [0.5]),
]
)
def load_train_transform_contour(config):
return transforms.Compose(
[
transforms.Resize((config.img_size, config.img_size), interpolation=config.contour_interpolation),
transforms.RandomCrop(config.img_size, padding=32, fill=0, padding_mode='constant'),
transforms.RandomHorizontalFlip(p=config.flip_p),
transforms.RandomApply([
NonUniformScaling(scale_x_range=config.scale_x, scale_y_range=config.scale_y),
transforms.RandomAffine(
degrees=config.degrees,
translate=config.translate,
scale=config.scale,
shear=config.shear
),
], p=config.apply_p),
transforms.Lambda(lambda x: x.point(lambda p: p > 50 and 255)),
transforms.ToTensor(),
]
)
def load_val_transform_img(config):
return transforms.Compose(
[
transforms.Resize((config.img_size, config.img_size), interpolation=config.img_interpolation),
transforms.ToTensor(),
transforms.Normalize([0.5], [0.5]),
]
)
def load_val_transform_contour(config):
return transforms.Compose(
[
transforms.Resize((config.img_size, config.img_size), interpolation=config.contour_interpolation),
transforms.Lambda(lambda x: x.point(lambda p: p > 50 and 255)),
transforms.ToTensor(),
]
)