-
Notifications
You must be signed in to change notification settings - Fork 546
/
dataloader.py
31 lines (29 loc) · 1.54 KB
/
dataloader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from torch.utils.data import DataLoader
from torchvision import datasets, transforms
def dataloader(dataset, input_size, batch_size, split='train'):
transform = transforms.Compose([transforms.Resize((input_size, input_size)), transforms.ToTensor(), transforms.Normalize(mean=(0.5, 0.5, 0.5), std=(0.5, 0.5, 0.5))])
if dataset == 'mnist':
data_loader = DataLoader(
datasets.MNIST('data/mnist', train=True, download=True, transform=transform),
batch_size=batch_size, shuffle=True)
elif dataset == 'fashion-mnist':
data_loader = DataLoader(
datasets.FashionMNIST('data/fashion-mnist', train=True, download=True, transform=transform),
batch_size=batch_size, shuffle=True)
elif dataset == 'cifar10':
data_loader = DataLoader(
datasets.CIFAR10('data/cifar10', train=True, download=True, transform=transform),
batch_size=batch_size, shuffle=True)
elif dataset == 'svhn':
data_loader = DataLoader(
datasets.SVHN('data/svhn', split=split, download=True, transform=transform),
batch_size=batch_size, shuffle=True)
elif dataset == 'stl10':
data_loader = DataLoader(
datasets.STL10('data/stl10', split=split, download=True, transform=transform),
batch_size=batch_size, shuffle=True)
elif dataset == 'lsun-bed':
data_loader = DataLoader(
datasets.LSUN('data/lsun', classes=['bedroom_train'], transform=transform),
batch_size=batch_size, shuffle=True)
return data_loader