-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathloader.py
25 lines (23 loc) · 949 Bytes
/
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
import torchvision
import torch
transform = torchvision.transforms.Compose([torchvision.transforms.ToTensor()])
def train_loader_fn(batch_size):
'''
It loads the training dataset. Takes one parameter:
batch_size: The batch size to be used during training
'''
train_dataset = torchvision.datasets.MNIST(root="~/torch_datasets", train=True, transform=transform, download=True)
train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=batch_size, shuffle=True)
return train_loader
def test_loader_fn(batch_size):
'''
It loads the testing dataset. Takes one parameter:
batch_size: The batch size to be passed to the loader
'''
test_dataset = torchvision.datasets.MNIST(
root="~/torch_datasets", train=False, transform=transform, download=True
)
test_loader = torch.utils.data.DataLoader(
test_dataset, batch_size=batch_size, shuffle=False
)
return test_loader