Adding Gaussion Noise in CIFAR10 dataset
If I want to add some Gaussion noise in the CIFAR10 dataset which is loaded by torchvision, how should I do it? Or, if I have defined a dataset by torch.utils.data.TensorDataset, how can I add more data samples there? Is any function like append( )? Thanks.
Shiyu
There’s a few ways you can do this. <SCODE>import random

class RandomNoise(object):
    def __init__(self, probability):
         self.probabilit = probability
    def __call__(self, img):
        if random.random() <= self.probability:
            return img.clone().normal_(0,1)
        return img
          
cifar10_dataset = torchvision.datasets.CIFAR10(root="...", download=True, transform=input_transform)
<ECODE> <SCODE>def __getitem__(self, index):
    if index < 50000:
        return super(MySubClass, self).__getitem__(index)
    else:
        return torch.Tensor(size).normal_(0,1), torch.Tensor(1).fill_(class_label)

<ECODE>
alykhantejani
Hi, I use torchvision.transform to do it, it has a lambda function which you can customized a funciton to add noise to the data. But the CIFAR10 image is small just 32 * 32 * 10, after add sp or gaussion noise on them, the final result seems like not well .
maxiaoyuzdz