-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
30 lines (23 loc) · 985 Bytes
/
Copy pathdata.py
File metadata and controls
30 lines (23 loc) · 985 Bytes
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
import torch
from torchvision import datasets, transforms
def mnist():
"""Return train and test dataloaders for MNIST."""
train_data, train_labels = [ ], [ ]
base_dir = r'/home/datameerkat/MLOPs/Course_material/dtu_mlops/data/corruptmnist'
for i in range(5):
train_data.append(torch.load(f"{base_dir}/train_images_{i}.pt"))
train_labels.append(torch.load(f"{base_dir}/train_target_{i}.pt"))
train_data = torch.cat(train_data, dim=0)
train_labels = torch.cat(train_labels, dim=0)
test_data = torch.load(f"{base_dir}/test_images.pt")
test_labels = torch.load(f"{base_dir}/test_target.pt")
print(train_data.shape)
print(train_labels.shape)
print(test_data.shape)
print(test_labels.shape)
train_data = train_data.unsqueeze(1)
test_data = test_data.unsqueeze(1)
return (
torch.utils.data.TensorDataset(train_data, train_labels),
torch.utils.data.TensorDataset(test_data, test_labels)
)