-
Notifications
You must be signed in to change notification settings - Fork 0
/
dataset.py
44 lines (40 loc) · 1.81 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
42
43
44
#!/usr/bin/env python
import torch
from torch.utils.data import Dataset, Dataloader
import torchvision
import torchvision.datasets as datasets
import torchvision.transforms as transforms
def load_cifar10(batch=128):
"""Load CIFAR10
"""
train_loader = DataLoader(
datasets.CIFAR10('./',
train=True,
download=True,
transform=transforms.Compose([
transforms.RandomHorizontalFlip(p=0.5),
transforms.RandomAffine(degree=0.2, scale=(0.8, 1.2)),
transforms.ToTensor(),
transforms.Normalize(
mean=[0.485, 0.456, 0.406],
std=[0.229,0.224, 0.225]
)
])),
batch_size=batch,
shuffle=True
)
test_loader = DataLoader(
datasets.CIFAR10('./',
train=False,
download=True,
transform=transforms.Compose([
transforms.ToTensor(),
transforms.Normalize(
mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225]
)
])),
batch_size=batch,
shuffle=True
)
return {'train': train_loader, 'test': test_loader}