def download_CIFAR10(train_transforms, test_transforms, batch_size=128, isCuda=Utility.isCuda()): """ Load CIFAR10 dataset. Uses the provided train_transforms and the test_transforms and create a object of Data. :param train_transforms: Transfomrations for train :param test_transforms: Transformations for test :param batch_size: Default value is 128 :param isCuda: Default value is True :return: Data """ dataloader_args = dict(shuffle=True, batch_size=batch_size, num_workers=4, pin_memory=True) if isCuda else dict( shuffle=True, batch_size=batch_size) train_data = datasets.CIFAR10("../data", train=True, transform=train_transforms, download=True) train_loader = torch.utils.data.DataLoader(train_data, **dataloader_args) test_data = datasets.CIFAR10("../data", train=False, transform=test_transforms, download=True) test_loader = torch.utils.data.DataLoader(test_data, **dataloader_args) print(f'Shape of a train data batch: {shape(train_loader)}') print(f'Shape of a test data batch: {shape(test_loader)}') print(f'Number of train images: {len(train_data.data)}') print(f'Number of test images: {len(test_data.data)}') classes = ('plane', 'car', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck') return Data(train_loader, test_loader, classes)
def loadTinyImagenet(data_folder, train_transforms, test_transforms, batch_size=128, isCuda=Utility.isCuda()): dataloader_args = dict(shuffle=True, batch_size=batch_size, num_workers=4, pin_memory=True) if isCuda else dict( shuffle=True, batch_size=batch_size) train_data = ImageNet.TinyImageNet(data_folder, train=True, transform=train_transforms) train_loader = torch.utils.data.DataLoader(train_data, **dataloader_args) test_data = ImageNet.TinyImageNet(data_folder, train=False, transform=test_transforms) test_loader = torch.utils.data.DataLoader(test_data, **dataloader_args) print(f'Shape of a train data batch: {shape(train_loader)}') print(f'Shape of a test data batch: {shape(test_loader)}') print(f'Number of train images: {len(train_data)}') print(f'Number of test images: {len(test_data)}') return Data(train_loader, test_loader, train_data.idx_class)