-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdatasets_aps_new.py
More file actions
186 lines (115 loc) · 5.1 KB
/
Copy pathdatasets_aps_new.py
File metadata and controls
186 lines (115 loc) · 5.1 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import os
import random
import numpy as np
import torch
import yaml
from torch.utils.data import Dataset
from tqdm import tqdm
class RSRP_dataset(Dataset):
def __init__(self, indexdir,BS, scale_worldsize=1):
super().__init__()
self.rsrpdata_dir='./data/RSRP_before.npy'
self.location='./data/location.txt'
self.dataset_index = np.loadtxt(indexdir)
self.rx_poses = torch.from_numpy(np.loadtxt(
self.location))
self.rx_poses = (self.rx_poses -BS[None,:])/ scale_worldsize
self.RSRPs = torch.from_numpy(np.load(
self.rsrpdata_dir))
self.nn_inputs, self.nn_RSRPs = self.load_data()
def load_data(self):
"""load data from datadir to memory for training
Returns
--------
nn_inputs : tensor. [n_samples, 3]. The inputs for training
position_grid:3
nn_RSRPs : tensor. [n_samples, n_rsrp = 32]. The RSRP (dB) as labels
"""
## NOTE! Large dataset may cause OOM?
nn_inputs = torch.tensor(np.zeros((len(self), 3)), dtype=torch.float32)
nn_RSRPs = torch.tensor(np.zeros((len(self), 32)), dtype=torch.float32)
data_counter = 0
for idx in tqdm(self.dataset_index, total=len(self.dataset_index)): # sample from dataset_index
idx=int(idx)
nn_inputs[data_counter] = self.rx_poses[idx]
nn_RSRPs[data_counter] = self.RSRPs[idx]
data_counter += 1
return nn_inputs, nn_RSRPs
def __len__(self):
return len(self.dataset_index)
def __getitem__(self, index):
return self.nn_inputs[index], self.nn_RSRPs[index]
class RSRP_dataset_test(Dataset):
def __init__(self, indexdir,BS, scale_worldsize=1):
super().__init__()
self.rsrpdata_dir='./data/RSRP_after.npy'
self.location='./data/location.txt'
self.dataset_index = np.loadtxt(indexdir)
self.rx_poses = torch.from_numpy(np.loadtxt(
self.location))
self.rx_poses = (self.rx_poses -BS[None,:])/ scale_worldsize
self.RSRPs = torch.from_numpy(np.load(
self.rsrpdata_dir))
self.nn_inputs, self.nn_RSRPs = self.load_data()
def load_data(self):
"""load data from datadir to memory for training
Returns
--------
nn_inputs : tensor. [n_samples, 3]. The inputs for training
position_grid:3
nn_RSRPs : tensor. [n_samples, n_rsrp = 32]. The RSRP (dB) as labels
"""
## NOTE! Large dataset may cause OOM?
nn_inputs = torch.tensor(np.zeros((len(self), 3)), dtype=torch.float32)
nn_RSRPs = torch.tensor(np.zeros((len(self), 32)), dtype=torch.float32)
data_counter = 0
for idx in tqdm(self.dataset_index, total=len(self.dataset_index)): # sample from dataset_index
idx=int(idx)
nn_inputs[data_counter] = self.rx_poses[idx]
nn_RSRPs[data_counter] = self.RSRPs[idx]
data_counter += 1
return nn_inputs, nn_RSRPs
def __len__(self):
return len(self.dataset_index)
def __getitem__(self, index):
return self.nn_inputs[index], self.nn_RSRPs[index]
class RSRP_APS_dataset(Dataset):
def __init__(self, indexdir,BS, scale_worldsize=1):
super().__init__()
self.rsrpdata_dir='./data/RSRP_after.npy'
self.apsdata_dir='./data/angular_power_spectrum.npy'
self.location='./data/location.txt'
self.dataset_index = np.loadtxt(indexdir)
self.rx_poses = torch.from_numpy(np.loadtxt(
self.location))
self.rx_poses = (self.rx_poses -BS[None,:])/ scale_worldsize
self.RSRPs = torch.from_numpy(np.load(
self.rsrpdata_dir))
self.APSs = torch.from_numpy(np.load(
self.apsdata_dir))
self.nn_inputs, self.nn_RSRPs, self.nn_APSs = self.load_data()
def load_data(self):
"""load data from datadir to memory for training
Returns
--------
nn_inputs : tensor. [n_samples, 3]. The inputs for training
position_grid:3
nn_RSRPs : tensor. [n_samples, n_rsrp = 32]. The RSRP (dB) as labels
nn_APSs : tensor. [n_samples, n_aps = 6552]. The APS as labels
"""
## NOTE! Large dataset may cause OOM?
nn_inputs = torch.tensor(np.zeros((len(self), 3)), dtype=torch.float32)
nn_RSRPs = torch.tensor(np.zeros((len(self), 32)), dtype=torch.float32)
nn_APSs = torch.tensor(np.zeros((len(self), 6552)), dtype=torch.float32)
data_counter = 0
for idx in tqdm(self.dataset_index, total=len(self.dataset_index)): # sample from dataset_index
idx=int(idx)
nn_inputs[data_counter] = self.rx_poses[idx]
nn_RSRPs[data_counter] = self.RSRPs[idx]
nn_APSs[data_counter] = self.APSs[idx]
data_counter += 1
return nn_inputs, nn_RSRPs, nn_APSs,
def __len__(self):
return len(self.dataset_index)
def __getitem__(self, index):
return self.nn_inputs[index], self.nn_RSRPs[index], self.nn_APSs[index]