-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransforms.py
More file actions
27 lines (18 loc) · 792 Bytes
/
transforms.py
File metadata and controls
27 lines (18 loc) · 792 Bytes
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
"""
Image transformation utilities (minimal version).
"""
from typing import Sequence
from torchvision import transforms
class GaussianBlur(transforms.RandomApply):
"""Apply Gaussian Blur to the PIL image."""
def __init__(self, *, p: float = 0.5, radius_min: float = 0.7, radius_max: float = 1.0):
keep_p = 1 - p
transform = transforms.GaussianBlur(kernel_size=9, sigma=(radius_min, radius_max))
super().__init__(transforms=[transform], p=keep_p)
IMAGENET_DEFAULT_MEAN = (0.485, 0.456, 0.406)
IMAGENET_DEFAULT_STD = (0.229, 0.224, 0.225)
def make_normalize_transform(
mean: Sequence[float] = IMAGENET_DEFAULT_MEAN,
std: Sequence[float] = IMAGENET_DEFAULT_STD,
) -> transforms.Normalize:
return transforms.Normalize(mean=mean, std=std)