-
Notifications
You must be signed in to change notification settings - Fork 155
/
data_loader.py
39 lines (36 loc) · 1.14 KB
/
data_loader.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
# encoding: utf-8
import torch
import random
from torchvision import datasets, transforms
def get_train_loader(args):
return torch.utils.data.DataLoader(
datasets.MNIST(
'mnist_data',
train = True,
download = True,
transform = transforms.Compose([
transforms.Lambda(lambda image: image.rotate(random.random() * args.angle * 2 - args.angle)),
transforms.ToTensor(),
]),
),
batch_size = args.batch_size,
shuffle = True,
num_workers = 4,
pin_memory = True if args.cuda else False,
)
def get_test_loader(args):
return torch.utils.data.DataLoader(
datasets.MNIST(
'mnist_data',
train = False,
download = True,
transform = transforms.Compose([
transforms.Lambda(lambda image: image.rotate(random.random() * args.angle * 2 - args.angle)),
transforms.ToTensor(),
]),
),
batch_size = args.batch_size,
shuffle = True,
num_workers = 4,
pin_memory = True if args.cuda else False,
)