Commit 65154d88 authored by Marius Laska's avatar Marius Laska

added augmentation option for multi-building uji

parent 614d1889
......@@ -42,6 +42,7 @@ class UJIndoorLocProviderFullGrid(UJIndoorLocProviderGrid):
def merge_dps(self):
data = []
aug_dicts = []
labels = []
grid_labels = []
......@@ -52,11 +53,17 @@ class UJIndoorLocProviderFullGrid(UJIndoorLocProviderGrid):
sum_max_idx = 0
sum_grid_idx = 0
mapping = {}
last_len_idx = 0
for key, dp in self.dps.items():
data.append(dp.data_tensor)
labels.append(dp.labels)
# aug encoding
aug_dict = {k+last_len_idx: v for (k, v) in dp.aug_encoding.items()}
aug_dicts.append(aug_dict)
last_len_idx += len(dp.data_tensor)
# num grid cells
num_row_l1 = np.ceil(dp.floorplan_height / dp.grid_size) + 1
num_col_l1 = np.ceil(dp.floorplan_width / dp.grid_size) + 1
......@@ -77,6 +84,13 @@ class UJIndoorLocProviderFullGrid(UJIndoorLocProviderGrid):
last_max_idx = sum_max_idx
last_grid_idx = sum_grid_idx
# merge aug dicts
full_aug_dict = {}
for a_d in aug_dicts:
for (k, v) in a_d.items():
full_aug_dict[k] = v
self.aug_encoding = full_aug_dict
self.data_tensor = np.concatenate(data, axis=0)
self.labels = np.concatenate(labels, axis=0)
self.grid_labels = np.concatenate(grid_labels, axis=0)
......@@ -93,18 +107,24 @@ class UJIndoorLocProviderFullGrid(UJIndoorLocProviderGrid):
self.standardize_data()
def _decode_grid_labels(self, grid_labels, y_true):
def _decode_grid_labels(self, grid_labels, y_true_labels, y_true):
sub = grid_labels[:, 4::5]
chosen = np.argmax(sub, axis=1)
decoded_preds = np.zeros((len(grid_labels), 6))
decoded_true = np.zeros((len(grid_labels), 4))
# find corresponding dp
for key, mapping in self.dp_mapping.items():
# y_pred
c_range = np.logical_and(chosen >= mapping[2], chosen < mapping[3])
dp_idx = np.where(c_range)[0]
dp = self.dps[key]
orig_labels = y_true[dp_idx, :]
# y_true
t_range = np.logical_and(y_true[:, 2] >= mapping[2], y_true[:, 2] < mapping[3])
t_idx = np.where(t_range)[0]
decoded_true[t_idx, 2:] = np.array(key)
decoded_labels = convert_from_2dim_overlapping_grid(
grid_labels[dp_idx, :], offset=mapping[2],
......@@ -113,20 +133,26 @@ class UJIndoorLocProviderFullGrid(UJIndoorLocProviderGrid):
decoded_preds[dp_idx, :4] = decoded_labels
decoded_preds[dp_idx, 4:] = np.array(key)
decoded_true[dp_idx, :2] = y_true_labels[dp_idx, :2]
print("Enc->DEC: {}".format(
np.array_equal(orig_labels, decoded_labels[:, :2])))
np.array_equal(y_true_labels[dp_idx, :], decoded_labels[:, :2])))
return decoded_preds
return decoded_preds, decoded_true
def decode_pipe_grid_labels(self, p: Pipeline):
y_pred_list = p.summary.y_pred
y_true_labels_list = p.summary.y_true_labels
y_true_list = p.summary.y_true
y_pred_list_new = []
for y_pred, y_true in zip(y_pred_list, y_true_list):
y_pred_list_new.append(self._decode_grid_labels(y_pred, y_true))
y_true_list_new = []
for y_pred, y_true_labels, y_true in zip(y_pred_list, y_true_labels_list, y_true_list):
y_p, y_t = self._decode_grid_labels(y_pred, y_true_labels, y_true)
y_pred_list_new.append(y_p)
y_true_list_new.append(y_t)
p.summary.y_pred = y_pred_list_new
p.summary.y_true = y_true_list_new
def get_bld_floor_combinations(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment