-
Notifications
You must be signed in to change notification settings - Fork 4
/
data_loader.py
executable file
·54 lines (45 loc) · 1.3 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
51
52
53
54
import torch.utils.data as data_utils
import numpy as np
import torch
import SIMLR
import os
def get_loader(features, batch_size, num_workers=1):
"""
Build and return a data loader.
"""
dataset = data_utils.TensorDataset(torch.Tensor(features))
loader = data_utils.DataLoader(dataset,
batch_size=batch_size,
shuffle = True, #set to True in case of training and False when testing the model
num_workers=num_workers
)
return loader
def learn_adj(x):
y = []
for t in x:
b = t.cpu().numpy()
y.append(b)
x = np.array(y)
batchsize = x.shape[0]
simlr = SIMLR.SIMLR_LARGE(1, batchsize/3, 0)
adj, _,_, _ = simlr.fit(x)
array = adj.toarray()
tensor = torch.Tensor(array).cuda()
return tensor
def to_tensor(x):
y = []
for t in x:
b = t.numpy()
y.append(b)
x = np.array(y)
x = x[0]
tensor = torch.Tensor(x)
return tensor
def create_dirs_if_not_exist(dir_list):
if isinstance(dir_list, list):
for dir in dir_list:
if not os.path.exists(dir):
os.makedirs(dir)
else:
if not os.path.exists(dir_list):
os.makedirs(dir_list)