-
Notifications
You must be signed in to change notification settings - Fork 2
/
data_loader.py
50 lines (42 loc) · 1.69 KB
/
data_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
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
import os
import torch
import torch.utils.data as data
import numpy as np
def data_loader(args):
if args.data_set == "air_quality":
train_dataset = air_quality(train=True)
test_dataset = air_quality(train=False)
train_loader = data.DataLoader(dataset = train_dataset,
batch_size = args.B,
num_workers=0,
drop_last=True,
shuffle=True)
test_loader = data.DataLoader(dataset = test_dataset,
batch_size = args.B,
num_workers=0,
drop_last=True,
shuffle=False)
return train_loader, test_loader
class air_quality(data.Dataset):
def __init__(
self,
train=True,
):
super(air_quality, self).__init__()
datasets = np.load("datasets/..")
self.train = train
self.train_data = torch.FloatTensor(datasets["train_data"])
self.train_masks = torch.FloatTensor(datasets["train_mask"])
self.test_data = torch.FloatTensor(datasets["test_data"])
self.test_masks = torch.FloatTensor(datasets["test_mask"])
def __getitem__(self, idx):
if self.train:
data, mask = self.train_data[idx], self.train_masks[idx]
else:
data, mask = self.test_data[idx], self.test_masks[idx]
return data, mask
def __len__(self):
if self.train:
return len(self.train_data)
else:
return len(self.test_data)