-
Notifications
You must be signed in to change notification settings - Fork 1
/
data_loader.py
21 lines (19 loc) · 916 Bytes
/
data_loader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from torchvision import datasets, transforms
import torch
import os
def load_training(root_path, dir, batch_size, kwargs):
transform = transforms.Compose(
[transforms.Resize([256, 256]),
transforms.RandomCrop(224),
transforms.RandomHorizontalFlip(),
transforms.ToTensor()])
data = datasets.ImageFolder(root=os.path.join(root_path, dir), transform=transform)
train_loader = torch.utils.data.DataLoader(data, batch_size=batch_size, shuffle=True, drop_last=True, **kwargs)
return train_loader
def load_testing(root_path, dir, batch_size, kwargs):
transform = transforms.Compose(
[transforms.Resize([224, 224]),
transforms.ToTensor()])
data = datasets.ImageFolder(root=os.path.join(root_path, dir), transform=transform)
test_loader = torch.utils.data.DataLoader(data, batch_size=batch_size, shuffle=True, **kwargs)
return test_loader