I have to randomly shuffle a fraction of the labels of a dataset. I’ve always done it doing the following (Example on CIFAR10):
train_dataset = dsets.CIFAR10(root='./data', 
                    train=True, 
                    transform=transform_train,
                    download=True)




for i in range(len(train_dataset.targets)):
if (i % 3 == 0):
    train_dataset.targets[i] = random.randint(0, 9)

Particularly, the code above shuffles 33% of the labels. I want to do the same using ImageFolder, prebuilt on torchvision, but somehow it fails to shuffle the labels without giving any error.
In fact, I have checked the training set, and what I noticed was that the label train_dataset[0][1] was unchanged. Furthermore, if I manually try to change it by doing
train_dataset[0][1] = random.randint(0,9)

It gives an error (which makes sense, it is a Tuple)
How can I shuffle a percentage of the labels? Thank you!