forked from facebookresearch/dino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_augmentations.py
81 lines (65 loc) · 1.89 KB
/
test_augmentations.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
69
70
71
72
73
74
75
76
77
78
79
80
81
import utils
from torchvision import transforms
from PIL import Image
from torchvision.transforms import functional as F
from main_dino import EdgePreservingFilter
import cv2
IMG_PATH = "test_imgs/3.png"
flip_and_color_jitter = transforms.Compose(
[
transforms.RandomHorizontalFlip(p=1),
transforms.RandomApply(
[
transforms.ColorJitter(
brightness=0.4, contrast=0.4, saturation=0.2, hue=0.1
)
],
p=1,
),
transforms.RandomGrayscale(p=0.2),
]
)
global_crop_aug_1 = [
transforms.RandomResizedCrop(
224,
scale=(0.14, 1),
interpolation=Image.BICUBIC,
),
flip_and_color_jitter,
# utils.GaussianBlur(1.0),
EdgePreservingFilter(),
]
global_crop1 = transforms.Compose(global_crop_aug_1)
global_crop_aug_2 = [
transforms.RandomResizedCrop(
224,
scale=(0.14, 1),
interpolation=Image.BICUBIC,
),
flip_and_color_jitter,
utils.GaussianBlur(0.0),
utils.Solarization(1.0),
]
global_crop2 = transforms.Compose(global_crop_aug_2)
local_crop_aug = [
transforms.RandomResizedCrop(
96,
scale=(0.05, 0.14),
interpolation=Image.BICUBIC,
),
flip_and_color_jitter,
# utils.GaussianBlur(p=0.5),
EdgePreservingFilter(sigma_s=60, sigma_r=0.4),
]
local_crop = transforms.Compose(local_crop_aug)
img = Image.open(IMG_PATH)
img.show(title="original")
# cv2.waitKey(0)
global_crop1_img = global_crop1(img)
global_crop1_img.show(title="flip, collor jitter, gaussian blur")
# global_crop2_img = global_crop2(img)
# global_crop2_img.show(title="flip, collor jitter, gaussian blur, solarization")
# local_crop_img = local_crop(img)
# local_crop_img.show(title="flip, collor jitter, gaussian blur")
# img_color_jitter = flip_and_color_jitter(img)
# img_color_jitter.show(title="flip, collor jitter")