def load(self): # Data Transformations transform = transforms.Compose([ transforms.RandomHorizontalFlip(), transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)) ]) # Dataset and Creating Train/Test Split train_set = torchvision.datasets.CIFAR10(root='./data', train=True, download=True, transform=transform) test_set = torchvision.datasets.CIFAR10(root='./data', train=False, download=True, transform=transform) # Dataloader Arguments & Test/Train Dataloaders dataloader_args = dict(shuffle=True, batch_size=self.batch_size_cuda, num_workers=self.num_workers, pin_memory=True) if has_cuda() else dict( shuffle=True, batch_size=self.batch_size_cpu) self.train_loader = torch.utils.data.DataLoader( train_set, **dataloader_args) self.test_loader = torch.utils.data.DataLoader(test_set, **dataloader_args)
def load(self): # Get Train and Test Data train_set, test_set = self._dataset() # Dataloader Arguments & Test/Train Dataloaders dataloader_args = dict(shuffle=True, batch_size=self.batch_size_cpu) if has_cuda(): dataloader_args.update(batch_size=self.batch_size_cuda, num_workers=self.num_workers, pin_memory=True) self.train_loader = torch.utils.data.DataLoader( train_set, **dataloader_args) self.test_loader = torch.utils.data.DataLoader(test_set, **dataloader_args)
import os import pdb import sys import torch.utils.data from torchvision import datasets, transforms from utils.has_cuda import * device = has_cuda() root_path = "C:/Users/gajanana_ganjigatti/Documents/Gaju_data/Quest/eva4/S12/tiny-imagenet-200/tiny-imagenet-200" dataloader_args = dict(batch_size=512, num_workers=2, pin_memory=True) if device else dict(batch_size=4) imagenet_traindir = os.path.join(root_path, 'train') imagenet_valdir = os.path.join(root_path, 'val') imagenet_testdir = os.path.join(root_path, 'test') imagenet_mean, imagenet_std = (0.485, 0.456, 0.406), (0.229, 0.224, 0.225) def tinyImgNet_dataloader(split='train'): if split == 'train': data_transform = datasets.ImageFolder( imagenet_traindir, transform=transforms.Compose([ transforms.Pad(padding=1, padding_mode="edge"), transforms.RandomHorizontalFlip(), transforms.RandomRotation(20), transforms.RandomCrop(size=(64, 64), padding=4), # transforms.RandomErasing(scale=(0.16, 0.16), ratio=(1, 1)), transforms.ToTensor(),