Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hackassin
GitHub Repository: hackassin/learnopencv
Path: blob/master/Bag-Of-Tricks-For-Image-Classification/model/augmentations.py
3442 views
1
import albumentations as A
2
import numpy as np
3
from albumentations.pytorch import ToTensorV2
4
5
6
def get_training_augmentation():
7
augmentations_train = A.Compose(
8
[
9
A.RandomResizedCrop(224, 224, scale=(0.8, 1.0)),
10
A.HorizontalFlip(),
11
A.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
12
ToTensorV2(),
13
],
14
)
15
return lambda img: augmentations_train(image=np.array(img))
16
17
18
def get_test_augmentation():
19
augmentations_val = A.Compose(
20
[
21
A.SmallestMaxSize(256),
22
A.CenterCrop(224, 224),
23
A.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
24
ToTensorV2(),
25
],
26
)
27
return lambda img: augmentations_val(image=np.array(img))
28
29
30
def unnormalize(tensor):
31
for channel, mean, std in zip(tensor, (0.485, 0.456, 0.406), (0.229, 0.224, 0.225)):
32
channel.mul_(std).add_(mean)
33
return tensor
34
35