-
Notifications
You must be signed in to change notification settings - Fork 40
/
dataloader.py
29 lines (26 loc) · 1.12 KB
/
dataloader.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
import os
import torch
from torchvision import datasets, transforms
def load_training(root_path, directory, batch_size):
transform = transforms.Compose(
[transforms.Resize([256, 256]),
transforms.RandomCrop(227),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])
]
)
data = datasets.ImageFolder(root=os.path.join(root_path, directory, 'images'), transform=transform)
train_loader = torch.utils.data.DataLoader(data, batch_size=batch_size, shuffle=True, drop_last=True)
return train_loader
def load_testing(root_path, directory, batch_size):
transform = transforms.Compose(
[transforms.Resize([227, 227]),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225]),
]
)
data = datasets.ImageFolder(root=os.path.join(root_path, directory, 'images'), transform=transform)
test_loader = torch.utils.data.DataLoader(data, batch_size=batch_size, shuffle=True)
return test_loader