-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtransforms.py
executable file
·31 lines (29 loc) · 1.13 KB
/
transforms.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
from torchvision import transforms
def init_transform_dict(input_res=224,
center_crop=256,
randcrop_scale=(0.5, 1.0),
color_jitter=(0, 0, 0),
norm_mean=(0.485, 0.456, 0.406),
norm_std=(0.229, 0.224, 0.225)):
normalize = transforms.Normalize(mean=norm_mean, std=norm_std)
tsfm_dict = {
'train': transforms.Compose([
transforms.RandomResizedCrop(input_res, scale=randcrop_scale),
transforms.RandomHorizontalFlip(),
transforms.ColorJitter(brightness=color_jitter[0], saturation=color_jitter[1], hue=color_jitter[2]),
normalize,
]),
'val': transforms.Compose([
transforms.Resize(center_crop),
transforms.CenterCrop(center_crop),
transforms.Resize(input_res),
normalize,
]),
'test': transforms.Compose([
transforms.Resize(center_crop),
transforms.CenterCrop(center_crop),
transforms.Resize(input_res),
normalize,
])
}
return tsfm_dict