-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcdatasets.py
153 lines (124 loc) Β· 4.31 KB
/
cdatasets.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
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
149
150
151
152
153
import torch
from torch.utils.data import Dataset
import torch.nn.functional as F
class UltrasoundDataset(Dataset):
"""Ultrasound RF Dataset"""
def __init__(self):
self.id = "og-ynorm-t1024"
self.in_path = "/home/peter/data/split"
self.y = torch.load("/home/peter/data/split/aeration1.pt") / 100.0
def __len__(self):
return self.y.shape[0]
def __getitem__(self, index):
if index not in range(len(self)):
raise IndexError(
f"Invalid index: {index}, Indices must be in {range(len(self))}"
)
x, y = (
torch.load(f"{self.in_path}/RF_{str(index)}.pt")[:1024, :, :],
# torch.load(f"{self.in_path}/RF_{str(index)}.pt"),
self.y[index],
)
x = x.unsqueeze(0)
# x = F.normalize(x)
return x, y
class RawNormUltrasoundDataset(Dataset):
"""Ultrasound RF Dataset"""
def __init__(self):
self.id = "raw-1509-norm"
self.in_path = "/home/peter/data/split"
self.y = torch.load("/home/peter/data/split/aeration1.pt") / 100.0
def __len__(self):
return self.y.shape[0]
def __getitem__(self, index):
if index not in range(len(self)):
raise IndexError(
f"Invalid index: {index}, Indices must be in {range(len(self))}"
)
x, y = (
torch.load(f"{self.in_path}/RF_{str(index)}.pt") / 30000.0,
self.y[index],
)
x = x.unsqueeze(0)
return x, y
class ReducedUltrasoundDataset(Dataset):
"""Ultrasound RF Dataset"""
def __init__(self):
self.id = "512x512-norm"
self.in_path = "/home/peter/data/split"
self.y = torch.load("/home/peter/data/split/aeration1.pt") / 100.0
def __len__(self):
return self.y.shape[0]
def __getitem__(self, index):
if index not in range(len(self)):
raise IndexError(
f"Invalid index: {index}, Indices must be in {range(len(self))}"
)
x, y = (
torch.load(f"{self.in_path}/RF_{str(index)}.pt")[:1024, :, :] / 30000.0,
self.y[index],
)
x, y = x.unsqueeze(0), y.unsqueeze(0)
x = F.avg_pool3d(x, (2, 4, 4))
x = x.flatten(2)
return x, y
class UltrasoundDataset1024x512(Dataset):
"""Ultrasound RF Dataset"""
def __init__(self):
self.id = "1024x512-norm"
self.in_path = "/home/peter/data/split"
self.y = torch.load("/home/peter/data/split/aeration1.pt") / 100.0
def __len__(self):
return self.y.shape[0]
def __getitem__(self, index):
if index not in range(len(self)):
raise IndexError(
f"Invalid index: {index}, Indices must be in {range(len(self))}"
)
x, y = (
torch.load(f"{self.in_path}/RF_{str(index)}.pt")[:1024, :, :] / 30000.0,
self.y[index],
)
x, y = x.unsqueeze(0), y.unsqueeze(0)
x = F.avg_pool3d(x, (1, 4, 4))
x = x.flatten(2)
return x, y
class CutUltrasoundDataset(Dataset):
"""Ultrasound RF Dataset"""
def __init__(self):
self.id = "cut-t1024-ynorm"
self.in_path = "/home/peter/data/split"
self.y = torch.load("/home/peter/data/split/aeration1.pt") / 100.0
def __len__(self):
return self.y.shape[0]
def __getitem__(self, index):
if index not in range(len(self)):
raise IndexError(
f"Invalid index: {index}, Indices must be in {range(len(self))}"
)
x, y = (
torch.load(f"{self.in_path}/RF_{str(index)}.pt")[200:1224, :, :],
# torch.load(f"{self.in_path}/RF_{str(index)}.pt"),
self.y[index],
)
x = x.unsqueeze(0)
# x = F.normalize(x)
return x, y
class SineDataset(Dataset):
"""
For testing purposes
Used to test train_net training loop
"""
def __init__(self):
self.id = "sin-wave"
def __len__(self):
return 2000
def __getitem__(self, index):
x = torch.rand((1,))
y = torch.sin(x)
return x, y
if __name__ == "__main__":
print("loading Ultrasound Dataset...")
ds_ultrasound = UltrasoundDataset1024x512()
x, y = ds_ultrasound[1000]
print(f"x, y: {x.shape}, {y.shape}")