File size: 1,647 Bytes
71c714a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Function used for visualization of data and results
Author: Shilpaj Bhalerao
Date: Jul 23, 2023
"""
# Third-Party Imports
import torch
import albumentations as A
from albumentations.pytorch import ToTensorV2


# Train Phase transformations
train_set_transforms = {
    'randomcrop': A.RandomCrop(height=32, width=32, p=0.2),
    'horizontalflip': A.HorizontalFlip(),
    'cutout': A.CoarseDropout(max_holes=1, max_height=16, max_width=16, min_holes=1, min_height=1, min_width=1, fill_value=[0.49139968*255, 0.48215827*255 ,0.44653124*255], mask_fill_value=None),
    'normalize': A.Normalize((0.49139968, 0.48215827, 0.44653124), (0.24703233, 0.24348505, 0.26158768)),
    'standardize': ToTensorV2(),
}

# Test Phase transformations
test_set_transforms = {
    'normalize': A.Normalize((0.49139968, 0.48215827, 0.44653124), (0.24703233, 0.24348505, 0.26158768)),
    'standardize': ToTensorV2()
}


class AddGaussianNoise(object):
    """
    Class for custom augmentation strategy
    """
    def __init__(self, mean=0., std=1.):
        """
        Constructor
        """
        self.std = std
        self.mean = mean

    def __call__(self, tensor):
        """
        Augmentation strategy to be implemented when called
        """
        return tensor + torch.randn(tensor.size()) * self.std + self.mean

    def __repr__(self):
        """
        Method to print more infor about the strategy
        """
        return f"{self.__class__.__name__}(mean={self.mean}, std={self.std})"

# Usage details
# transforms = transforms.Compose([
#     transforms.ToTensor(),
#     AddGaussianNoise(0., 1.0),
#     ])