from torch.utils.data import ConcatDataset from torchvision.datasets import CIFAR10, MNIST # Define the datasets to concatenate cifar = CIFAR10(root='./data', train=True, download=True) mnist = MNIST(root='./data', train=True, download=True) # Concatenate the datasets concat_dataset = ConcatDataset([cifar, mnist])
from torch.utils.data import ConcatDataset from torchvision.datasets import CIFAR10 from torchvision.transforms import Compose, RandomCrop, RandomHorizontalFlip, ToTensor # Define the original dataset cifar = CIFAR10(root='./data', train=True, download=True) # Define different data augmentations augmentation1 = Compose([RandomCrop(32, padding=4), RandomHorizontalFlip(), ToTensor()]) augmentation2 = Compose([RandomCrop(32, padding=4), ToTensor()]) augmentation3 = Compose([RandomHorizontalFlip(), ToTensor()]) # Apply the data augmentations to the original dataset cifar_aug1 = CIFAR10(root='./data', train=True, download=True, transform=augmentation1) cifar_aug2 = CIFAR10(root='./data', train=True, download=True, transform=augmentation2) cifar_aug3 = CIFAR10(root='./data', train=True, download=True, transform=augmentation3) # Concatenate the datasets with different augmentations concat_dataset = ConcatDataset([cifar, cifar_aug1, cifar_aug2, cifar_aug3])This code defines an original CIFAR10 dataset and creates three different data augmentations using the Compose function from the torchvision.transforms module. It then applies those augmentations to the original dataset using the transform argument when creating new CIFAR10 instances. Finally, it concatenates the original dataset with the three augmented versions into a single dataset using the ConcatDataset class.