-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset.py
41 lines (35 loc) · 1.58 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
38
39
40
41
import torchvision
from pathlib import Path
from torch.utils import data
import torchvision.transforms as transforms
def get_Dataloader(mode,batch_size):
transform = transforms.Compose([
transforms.Pad(4),
transforms.RandomHorizontalFlip(),
transforms.RandomCrop(32),
transforms.ToTensor()])
if Path('./data/').exists() == False :
Path('./data/').mkdir()
else:
pass
if mode == 'train':
_dataset = torchvision.datasets.CIFAR10(root='../homework-9/data/',
train=True,
transform=transform,
download=True)
elif mode == 'val':
_dataset = torchvision.datasets.CIFAR10(root='../homework-9/data/',
train=False,
transform=transforms.ToTensor(),
download=True)
elif mode == 'test':
_dataset = torchvision.datasets.CIFAR10(root='../homework-9/data/',
train=False,
transform=transforms.ToTensor(),
download=True)
if mode == 'train':
shuffle = True
else:
shuffle = False
data_loader = data.DataLoader(_dataset,batch_size = batch_size,shuffle=shuffle)
return data_loader