forked from pclubiitk/model-zoo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdataset.py
38 lines (28 loc) · 1.78 KB
/
dataset.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
32
33
34
35
36
37
import numpy as np
import torch
import torch.utils.data
import torchvision
from torchvision import datasets
import torchvision.models
import torchvision.transforms as transforms
def get_loader(batch_size, num_workers, image_size, ndata):
if ndata == 'cifar10':
dataset = datasets.CIFAR10(root='./content', train=True, download=True,
transform=transforms.Compose([transforms.Resize(image_size),
transforms.CenterCrop(image_size),
transforms.ToTensor(),
transforms.Normalize((0.5,0.5,0.5), (0.5,0.5,0.5))]))
if ndata == 'mnist':
dataset = datasets.MNIST(root='./content', train=True, download=True,
transform=transforms.Compose([transforms.Resize(image_size),
transforms.CenterCrop(image_size),
transforms.ToTensor(),
transforms.Normalize((0.5,), (0.5,))]))
if ndata == 'fmnist':
dataset = datasets.FashionMNIST(root='./content', train=True, download=True,
transform=transforms.Compose([transforms.Resize(32),
transforms.CenterCrop(32),
transforms.ToTensor(),
transforms.Normalize((0.5,), (0.5,))]))
dataloader = torch.utils.data.DataLoader(dataset, batch_size=batch_size, num_workers= num_workers ,shuffle=True)
return dataloader