-
Notifications
You must be signed in to change notification settings - Fork 1
/
transforms.py
executable file
·68 lines (63 loc) · 1.79 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
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
import albumentations as A
from albumentations.pytorch import ToTensorV2
from torchvision import transforms
# Define the training tranforms
def get_train_aug():
return A.Compose([
A.MotionBlur(blur_limit=3, p=0.5),
A.Blur(blur_limit=3, p=0.5),
A.RandomBrightnessContrast(
brightness_limit=0.2, p=0.5
),
A.ColorJitter(p=0.5),
# A.Rotate(limit=10, p=0.2),
A.RandomGamma(p=0.2),
A.RandomFog(p=0.2),
# A.RandomSunFlare(p=0.1),
# `RandomScale` for multi-res training,
# `scale_factor` should not be too high, else may result in
# negative convolutional dimensions.
# A.RandomScale(scale_limit=0.15, p=0.1),
A.Normalize(
(0.485, 0.456, 0.406),
(0.229, 0.224, 0.225)
),
ToTensorV2(p=1.0),
], bbox_params={
'format': 'pascal_voc',
'label_fields': ['labels']
})
def get_train_transform():
return A.Compose([
A.Normalize(
(0.485, 0.456, 0.406),
(0.229, 0.224, 0.225)
),
ToTensorV2(p=1.0),
], bbox_params={
'format': 'pascal_voc',
'label_fields': ['labels']
})
def get_valid_transform():
return A.Compose([
A.Normalize(
(0.485, 0.456, 0.406),
(0.229, 0.224, 0.225)
),
ToTensorV2(p=1.0),
], bbox_params={
'format': 'pascal_voc',
'label_fields': ['labels']
})
# Transforms.
def detect_transform(image):
transform = transforms.Compose([
transforms.ToPILImage(),
transforms.Resize((300, 300)),
transforms.ToTensor(),
transforms.Normalize(
mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225]
)
])
return transform(image)