-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhcp.py
More file actions
executable file
·148 lines (136 loc) · 5.25 KB
/
hcp.py
File metadata and controls
executable file
·148 lines (136 loc) · 5.25 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
from __future__ import print_function
import numpy
import torch.utils.data as data
import torch
import random
import h5py
class PointSet_pair(data.Dataset):
def __init__(self,vec,gt,transform=None,n_points=[1024],val=False):
self.vec=vec
self.tpvt=gt
self.transform = transform
self.n_points=n_points
self.val=val
def __getitem__(self, index: int):
feat_points=self.vec[index]
tracts=list(feat_points.keys())
feat=None
for i,tract in enumerate(tracts):
feat_tract=feat_points[tract]
# if self.val:
# numpy.random.seed(0)
# random.seed(0)
id1 = numpy.random.randint(feat_tract.shape[0], size=20000)
id = random.sample(list(numpy.unique(id1)), self.n_points[i])
feat1 = feat_tract[id]
# if index==1:
# print(id[:3])
if feat is None:
feat=feat1
else:
feat=numpy.concatenate((feat,feat1),0)
label = self.tpvt[index]
feat_1 = torch.tensor(feat.T, dtype=torch.float)
label_1 = torch.tensor(label, dtype=torch.float)
index2=random.randint(0,len(self.vec)-1)
feat_points = self.vec[index2]
tracts=list(feat_points.keys())
feat=None
for i,tract in enumerate(tracts):
feat_tract=feat_points[tract]
id1 = numpy.random.randint(feat_tract.shape[0], size=20000)
id2 = random.sample(list(numpy.unique(id1)), self.n_points[i])
feat1 = feat_tract[id2]
if feat is None:
feat=feat1
else:
feat=numpy.concatenate((feat,feat1),0)
label = self.tpvt[index2]
feat_2 = torch.tensor(feat.T, dtype=torch.float)
label_2 = torch.tensor(label, dtype=torch.float)
return feat_1,label_1,feat_2,label_2,numpy.array(id)
def __len__(self) -> int:
return len(self.vec)
class PointSet(data.Dataset):
def __init__(self,vec,gt,transform=None,n_points=[1024],val=False):
self.vec=vec
self.tpvt=gt
self.transform = transform
self.n_points=n_points
self.val = val
def __getitem__(self, index: int):
#print(index)
feat_points=self.vec[index]
tracts=list(feat_points.keys())
#n_points_sub=int(self.n_points/len(tracts))
feat=None
for i,tract in enumerate(tracts):
feat_tract=feat_points[tract]
# if self.val:
# numpy.random.seed(0)
# random.seed(0)
id1 = numpy.random.randint(feat_tract.shape[0], size=20000)
id = random.sample(list(numpy.unique(id1)), self.n_points[i])
feat1 = feat_tract[id]
if feat is None:
feat=feat1
else:
feat=numpy.concatenate((feat,feat1),0)
# id = numpy.random.choice(list(range(feat_points.shape[0])), 1024
# , replace=False)
#id = random.sample(list(range(20000)), 1024)
#id = numpy.random.choice(list(range(feat_points.shape[0])), 1024, replace=False)
label = self.tpvt[index]
feat = torch.tensor(feat.T, dtype=torch.float)
label = torch.tensor(label, dtype=torch.float)
# if self.transform is not None:
# img = self.transform(img)
return feat,label
def __len__(self) -> int:
return len(self.vec)
class Fiber_pair_vis(data.Dataset):
def __init__(self,vec,gt,transform=None,n_points=1024):
self.vec=vec
self.tpvt=gt
self.transform = transform
self.n_points=n_points
def __getitem__(self, index: int):
feat_points=self.vec[index]
feat=feat_points[self.n_points*index:self.n_points*(index+1),:]
label = self.tpvt[index]
feat = torch.tensor(feat.T, dtype=torch.float)
label = torch.tensor(label, dtype=torch.float)
# if self.transform is not None:
# img = self.transform(img)
return feat,label
def __len__(self) -> int:
return len(self.vec)
class Fiber_sub(data.Dataset):
def __init__(self,vec,gt,transform=None,n_points=[1024]):
self.vec=vec
self.tpvt=gt
self.transform = transform
self.n_points=n_points
def __getitem__(self, index: int):
#print(index)
sub_id=self.vec[index]
ff = h5py.File('/media/annabelchen/DataShare/deepClustering/HCPTestingData/tractography_prediction/tract_feats/subjects/{}.h5'.format(sub_id))
tracts=list(ff.keys())
feat=None
for i,tract in enumerate(tracts):
feat_tract=ff[tract][:]
id1 = numpy.random.randint(feat_tract.shape[0], size=20000)
id = random.sample(list(numpy.unique(id1)), self.n_points[i])
feat1 = feat_tract[id]
if feat is None:
feat=feat1
else:
feat=numpy.concatenate((feat,feat1),0)
label = self.tpvt[index]
feat = torch.tensor(feat.T, dtype=torch.float)
label = torch.tensor(label, dtype=torch.float)
# if self.transform is not None:
# img = self.transform(img)
return feat,label
def __len__(self) -> int:
return len(self.vec)