-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloaders.py
62 lines (49 loc) · 1.31 KB
/
loaders.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
Implements loaders for training and testing data.
"""
from torch.utils.data import DataLoader
from torchvision.transforms import Compose
from dataset import FacialLandmarksDataset
from transformations import (
Rescale,
RandomCrop,
Normalize,
ToTensor
)
__author__ = "Victor mawusi Ayi <ayivima@hotmail.com>"
data_transform = Compose([
Rescale(250),
RandomCrop(224),
Normalize(),
ToTensor()
])
def train_dataset(transforms_pipe=data_transform):
return FacialLandmarksDataset(
keypoints_file='/data/training_frames_keypoints.csv',
images_dir='/data/training/',
transforms=transforms_pipe
)
def test_dataset(transforms_pipe=data_transform):
return FacialLandmarksDataset(
keypoints_file='/data/test_frames_keypoints.csv',
images_dir='/data/test/',
transforms=transforms_pipe
)
def trainloader(batch_size=10):
return DataLoader(
train_dataset(),
batch_size=batch_size,
shuffle=True
)
def testloader(batch_size=10):
return DataLoader(
test_dataset(),
batch_size=batch_size,
shuffle=True
)
def dataloaders(batch_size=10):
"""Returns loaders for training and testing data."""
return (
trainloader(batch_size),
testloader(batch_size)
)