forked from hliulab/atmtcr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataloader.py
36 lines (30 loc) · 1.07 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
30
31
32
33
34
35
36
import torch
import torchvision
import folders
import numpy as np
import random
seed = 1
torch.manual_seed(seed)
torch.cuda.manual_seed(seed)
torch.cuda.manual_seed_all(seed)
np.random.seed(seed)
random.seed(seed)
class DataLoader(object):
def __init__(self, batch_size=1, istrain=True):
self.batch_size = batch_size
self.istrain = istrain
def get_data(self, data):
if self.istrain:
dataloader = torch.utils.data.DataLoader(
data, batch_size=self.batch_size, shuffle=True, pin_memory=True, num_workers=0)
else:
dataloader = torch.utils.data.DataLoader(
data, batch_size=1, shuffle=True)
return dataloader
if __name__ == '__main__':
dataset = folders.Folder()
tr_data = folders.Dataset(dataset.train_data, dataset.train_label)
te_data = folders.Dataset(dataset.test_data, dataset.test_label)
train_data = DataLoader(batch_size=64, istrain=True).get_data(tr_data)
test_data = DataLoader(istrain=False).get_data(te_data)
print("1")