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
| def create_transforms(target_size, *, is_training=True) -> A.Compose:
"""Create image augmentation and normalization transformations.
Args:
target_size: The desired height and width for the images.
is_training: A boolean indicating whether to apply training-specific augmentations.
Returns:
An `A.Compose` object containing the sequence of transformations.
"""
transforms_list = [
A.Resize(height=target_size, width=target_size, p=1.0),
]
if is_training:
transforms_list.extend(
[
A.HorizontalFlip(p=0.5),
A.VerticalFlip(p=0.5),
A.Rotate(limit=30, p=0.5),
A.ColorJitter(
brightness=0.2,
contrast=0.2,
saturation=0.2,
hue=0.05,
p=0.5,
),
A.RandomResizedCrop(
size=(target_size, target_size),
scale=(0.8, 1.0),
ratio=(0.75, 1.33),
p=0.5,
),
],
)
transforms_list.append(
A.Normalize(
mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225],
max_pixel_value=255.0,
),
)
return A.Compose(transforms_list)
|