Commit 1bc428ea authored by Marius Laska's avatar Marius Laska

new BBOX model (tanh activation), data augmentation (overlapping cell encoding)

parent 7f409539
import numpy as np
from il_pipeline.pipeline import Pipeline
from il_pipeline.utility.storable import Storable
import matplotlib.pyplot as plt
from analysis.plot_analysis import get_avg_box_size
from analysis.visualize_learning_progress import \
convert_from_2dim_overlapping_grid
from main import calc_acc_c
import os
def main():
plt.figure()
f2 = "../evaluation/UJIndoorLoc/b0/f2/final/output/REG_{}"
dist_list = []
size_list = []
for idx in range(10):
p: Pipeline = Storable.load(f2.format(idx+1))
y_true = np.concatenate(p.summary.y_true_labels, axis=0)
y_pred = np.concatenate(p.summary.y_pred, axis=0)
n = len(y_true)
dist = np.sort(np.linalg.norm(y_pred - y_true, axis=1))
size = np.pi * np.square(dist)
acc = [i/n for i in range(n)]
dist_list.append(dist)
size_list.append(size)
# plt.plot(size, acc)
size_avg = np.mean(np.stack(size_list, axis=1), axis=1)
plt.plot(size_avg, [i/n for i in range(n)], linestyle="dashed")
# compare BBOX values
f1 = "../evaluation/UJIndoorLoc/b0/f2/final/output/BBOX_{}l_{}o{}_{}"
for aug in ["_aug", ""]:
for l in [1,2]:#, 2]:
for o in [5, 4, 3]:
b_size_list = []
acc_box_list = []
for idx in [1,2,3]:
file = f1.format(l, o, aug, idx)
if not os.path.exists(file):
print(file)
continue
p: Pipeline = Storable.load(file)
convert_from_2dim_overlapping_grid(p, grid_size=40, quantile=False,
store=True,
average_samples=True)
y_true = np.concatenate(p.summary.y_true_labels, axis=0)
y_pred = np.concatenate(p.summary.y_pred, axis=0)
acc_box, wrong_mask, correct_mask = calc_acc_c(y_true, y_pred)
b_size = get_avg_box_size(p)
acc_box_list.append(acc_box)
b_size_list.append(b_size)
if aug == "_aug":
c = "r"
else:
c = "g"
if l == 1:
m = "v"
elif l == 2:
m = "^"
elif l == 3:
m = ">"
plt.scatter(b_size, acc_box, color=c, marker=m)
# plot mean of 3 attemps
plt.scatter(np.mean(np.array(b_size_list)), np.mean(np.array(acc_box_list)), color=c, marker=m)
plt.show()
if __name__ == "__main__":
main()
\ No newline at end of file
......@@ -2,22 +2,32 @@ from il_pipeline.pipeline import Pipeline
from il_pipeline.utility.storable import Storable
import numpy as np
import pandas as pd
from mgwr.gwr import GWR, MGWR, GWRResults
from mgwr.sel_bw import Sel_BW
from shapely.geometry import Point
from pkg_resources import resource_filename
from analysis.visualize_learning_progress import convert_from_2dim_grid
from analysis.visualize_learning_progress import convert_from_2dim_grid, convert_from_2dim_2layer_grid, convert_from_2dim_3layer_grid, convert_from_2dim_overlapping_grid
from statsmodels.regression.linear_model import OLS
from statsmodels.tools import add_constant
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
from base.floor_plan_plot import FloorPlanPlotRec
def main(dir_p="../evaluation/lohan/evaluation/new_knn/output/", f_idx=0):
bbox: Pipeline = Storable.load(dir_p + "BBOX")
convert_from_2dim_grid(bbox, grid_size=40, quantile=False, store=True,
average_samples=True)
reg: Pipeline = Storable.load(dir_p + "REG")
convert_from_2dim_overlapping_grid(bbox, grid_size=40, quantile=False,
store=True,
average_samples=True)
#convert_from_2dim_grid(bbox, grid_size=40, quantile=False, store=True,
# average_samples=True)
reg: Pipeline = Storable.load(dir_p + "REG_DEEP") # Storable.load("../evaluation/simulation/evaluation/big_2/output/" + "REG") #Storable.load("../evaluation/simulation/evaluation/big_2/output/REG")
knn: Pipeline = Storable.load(dir_p + "KNN")
#knn: Pipeline = Storable.load(dir_p + "KNN")
#bbox_m: Pipeline = Storable.load(
# "/Users/mariuslaska/PycharmProjects/boxprediction/evaluation/lohan/evaluation/grid_test/output/BBOX_TEST_3_v5")
......@@ -30,7 +40,7 @@ def main(dir_p="../evaluation/lohan/evaluation/new_knn/output/", f_idx=0):
# predicted positions (of fold f_idx)
y_pred_box = bbox.summary.y_pred[f_idx]
y_pred_reg = reg.summary.y_pred[f_idx]
y_pred_knn = knn.summary.y_pred[f_idx]
#y_pred_knn = knn.summary.y_pred[f_idx]
#y_pred_bbox_m = bbox_m.summary.y_pred[f_idx]
......@@ -49,11 +59,36 @@ def main(dir_p="../evaluation/lohan/evaluation/new_knn/output/", f_idx=0):
print("reg_mse: {}".format(reg_mse))
img = resource_filename('data', 'lohan/CrowdsourcedDS1floor.png')
(train, test) = bbox.data_provider.splits_indices[f_idx]
fp = FloorPlanPlotRec((200, 80), 2, floorplan_bg_img=img)
fp.draw_points(bbox.data_provider.labels[train, 0],
bbox.data_provider.labels[train, 1], color='g', alpha=0.5)
#fp.draw_points(bbox.data_provider.labels[test, 0],
# bbox.data_provider.labels[test, 1], color='r',
# alpha=0.5)
#fp.show_plot()
# for each prediction => find bbox of TD with close
SIM_THRESHOLD = 5
sim_size = np.zeros(len(test))
for t_idx, t in enumerate(test):
t_data = bbox.data_provider.data_tensor[t, :]
#diff_to_t = np.linalg.norm(bbox.data_provider.data_tensor - t_data, axis=1)
diff_to_t = np.linalg.norm(bbox.data_provider.labels - bbox.data_provider.labels[t, :], axis=1)
sim_mask = np.where(diff_to_t < SIM_THRESHOLD)[0]
sim_labels = bbox.data_provider.labels[sim_mask, :]
max_l = np.max(sim_labels, axis=0)
min_l = np.min(sim_labels, axis=0)
#sim_size[t_idx] = (max_l[0] - min_l[0]) * (max_l[1] - min_l[1])
sim_size[t_idx] = len(sim_labels)
# reference error of kNN model (also component-wise)
knn_error = np.linalg.norm(y_true - y_pred_knn, axis=1)
knn_error_x = np.abs(y_true - y_pred_knn)[:, 0]
knn_error_y = np.abs(y_true - y_pred_knn)[:, 1]
knn_mse = np.mean(knn_error)
#knn_error = np.linalg.norm(y_true - y_pred_knn, axis=1)
#knn_error_x = np.abs(y_true - y_pred_knn)[:, 0]
#knn_error_y = np.abs(y_true - y_pred_knn)[:, 1]
#knn_mse = np.mean(knn_error)
knn_error = box_error
knn_error_x = np.abs(y_true - y_pred_box[:, :2])[:, 0]
......@@ -94,6 +129,35 @@ def main(dir_p="../evaluation/lohan/evaluation/new_knn/output/", f_idx=0):
evaluate_correlation(size_x, knn_error_y, "error_y -> size_x", summary)
evaluate_correlation(size_y, knn_error_x, "error_x -> size_y", summary)
evaluate_correlation(sim_size, y_true[:, 0], "num_around -> size", summary)
evaluate_correlation(box_size, y_true[:, 0], "x_pos -> size", summary)
evaluate_correlation(box_size, y_true[:, 1], "y_pos -> size", summary)
evaluate_correlation(box_size, np.mean(y_true, axis=1), "pos -> size", summary)
evaluate_correlation(box_size, np.stack((y_true[:, 0], y_true[:, 1], knn_error_x, knn_error_y), axis=1), "all -> size", summary)
#plt.figure()
#plt.scatter(knn_error, box_size)
#plt.show()
coords = [(l[0], l[1]) for l in y_true]
geometry = [Point(xy) for xy in zip(coords)]
df = pd.DataFrame(list(zip(y_pred_box[:,0], y_pred_box[:, 1], knn_error_x, knn_error_y, box_size)), columns=['x', 'y', 'error_x', 'error_y', 'box_size'])
df.plot.scatter(x='x', y='y', c='box_size', colormap='viridis')
plt.axis('equal')
df_2 = pd.DataFrame(list(
zip(y_true[:, 0], y_true[:, 1], knn_error_x, knn_error_y,
box_size)), columns=['x', 'y', 'error_x', 'error_y', 'box_size'])
df_2.plot.scatter(x='x', y='y', c='box_size', colormap='viridis')
#y = box_size.reshape(-1, 1)
#X = np.stack((knn_error_x, knn_error_y), axis=1)
#gwr(coords, y, X)
plt.axis('equal')
plt.show()
#
# Correlation between std of Monte-Carlo-Dropout Model (center, size, error)
# with kNN model error
......@@ -107,14 +171,16 @@ def main(dir_p="../evaluation/lohan/evaluation/new_knn/output/", f_idx=0):
#evaluate_correlation(center_std, knn_error, "error -> std(center) [MCD]", summary)
summary["f"] += [f_idx] * 5
summary["f"] += [f_idx] * 10
return summary
def evaluate_correlation(y, x, type, summary):
if len(x.shape) == 1:
x = x.reshape(-1, 1)
regr = OLS(y,
add_constant(x.reshape(-1, 1))).fit()
add_constant(x)).fit()
summary["y"].append(regr.params[0])
summary["beta"].append(regr.params[1])
summary["p_val"].append(regr.pvalues[1])
......@@ -130,8 +196,8 @@ def generate_correlation_df():
corr_type = []
fold_idx = []
for f_idx in range(5):
summary = main("../evaluation/simulation/evaluation/big/output/", f_idx=f_idx)
for f_idx in range(1):
summary = main("../evaluation/UJIndoorLoc/b0/f2/overlap/output/", f_idx=f_idx)
y_intercepts += summary["y"]
betas += summary["beta"]
......@@ -149,6 +215,18 @@ def generate_correlation_df():
return df
def gwr(g_coords, g_y, g_X):
gwr_selector = Sel_BW(g_coords, g_y, g_X)
gwr_bw = gwr_selector.search(bw_min=2)
print(gwr_bw)
gwr_results: GWRResults = GWR(g_coords, g_y, g_X, gwr_bw).fit()
print(gwr_results.localR2[0:10])
print(gwr_results.summary())
filter_t = gwr_results.filter_tvals()
if __name__ == "__main__":
df = generate_correlation_df()
......
......@@ -2,19 +2,23 @@ from il_pipeline.pipeline import Pipeline
from il_pipeline.utility.storable import Storable
import numpy as np
import math
import matplotlib.pyplot as plt
from pkg_resources import resource_filename
from analysis.evaluate_circle import get_success_rate, get_avg_circle_size, \
get_dist_from_circles, get_dist_from_box
from analysis.visualize_learning_progress import convert_from_grid, \
convert_from_2dim_grid
convert_from_2dim_grid, convert_from_2dim_2layer_grid, convert_from_2dim_overlapping_grid
from base.floor_plan_plot import FloorPlanPlotRec
from main import calc_acc_c, center_diff, calc_acc_elipse
from analysis.plot_analysis import find_radius_for_acc, get_avg_box_size #, find_acc_of_area
from analysis.visualize_quantile import get_acc_and_size
from base.acs import bbox_acs, reg_acs
PI = 3.14159265359
lambda_const = 1.0
def main(p_reg_f=None, p_circle_f=None, p_quantile_f=None, p_box_f=None, vis_idx=(0,1000)):
......@@ -37,8 +41,11 @@ def main(p_reg_f=None, p_circle_f=None, p_quantile_f=None, p_box_f=None, vis_idx
p_box: Pipeline = Storable.load(p_box_f)
#g_s = p_box.data_provider.
g_s = p_box.data_provider.grid_size
convert_from_2dim_grid(p_box, grid_size=g_s, quantile=False, store=True,
convert_from_2dim_overlapping_grid(p_box, grid_size=g_s, quantile=False, store=True,
average_samples=True)
#convert_from_2dim_grid(p_box, grid_size=g_s, quantile=False, store=True,
# average_samples=True)
# compute avg box size per fold
avg_box_size = [np.mean(np.prod(pred[:, 2:], axis=1)) for pred in p_box.summary.y_pred]
......@@ -102,15 +109,22 @@ def main(p_reg_f=None, p_circle_f=None, p_quantile_f=None, p_box_f=None, vis_idx
y_true = np.concatenate(p_box.summary.y_true_labels, axis=0)
y_pred = np.concatenate(p_box.summary.y_pred, axis=0)
acc_box, wrong_mask = calc_acc_c(y_true, y_pred)
acc_box, wrong_mask, correct_mask = calc_acc_c(y_true, y_pred)
acs = bbox_acs(p_box, lambda_const=lambda_const)
#acc_box = calc_acc_elipse(y_true, y_pred)
#b_size = np.mean(PI * np.prod(y_pred[:, 2:]/2.0, axis=1))
b_size = get_avg_box_size(p_box)
corr_size = np.mean(y_pred[correct_mask, 2] * y_pred[correct_mask, 3])
wrong_size = np.mean(y_pred[wrong_mask, 2] * y_pred[wrong_mask, 3])
print("acc: {}".format(acc_box))
print("center-dist: {}".format(center_diff(y_true, y_pred)))
print("avg_center: {}".format(np.mean(y_pred[:, :2], axis=0)))
print("avg_box_size: {}".format(b_size))
print("ACS: {}".format(acs))
print("avg_box_size (correct): {}".format(corr_size))
print("avg_box_size (wrong): {}".format(wrong_size))
dist = get_dist_from_box(p_box)
print("DEVIATION: {}".format(dist))
......@@ -130,6 +144,8 @@ def main(p_reg_f=None, p_circle_f=None, p_quantile_f=None, p_box_f=None, vis_idx
radius_b = None
if p_reg is not None:
# move closer
#move_pred_closer(p_reg, dist=0.6)
print("\n --------REG--------- \n")
y_true = np.concatenate(p_reg.summary.y_true_labels, axis=0)
......@@ -147,17 +163,22 @@ def main(p_reg_f=None, p_circle_f=None, p_quantile_f=None, p_box_f=None, vis_idx
#radius_b = find_radius_for_acc(p_reg, accuracy=acc_quantile)
#print("SIZE_REG (QUANTILE): {}".format(PI * math.pow(radius_b, 2)))
acs = reg_acs(p_reg, lambda_const=lambda_const, radius=radius_b)
print("ACS: {}".format(acs))
plt.show()
#radius_b = 10
visualize(p_reg, p_circle, p_quantile, p_box, radius_b, vis_idx)
def visualize(p_reg: Pipeline=None, p_circle: Pipeline=None, p_quantile: Pipeline=None, p_box: Pipeline=None, radius=9.0, vis_idx=(0,20)):
img = "../evaluation/gia/gia_floor_4.jpg"
#img = "../evaluation/gia/gia_floor_4.jpg"
#fp_dims = (83.32, 17.16)
#img = resource_filename('data', 'lohan/CrowdsourcedDS1floor.png')
img = resource_filename('data', 'lohan/CrowdsourcedDS1floor.png')
#img = "/Users/mariuslaska/sciebo/SensorDatenGIA/Gebäude STL/transparent/2130_4.og.png"
fp_dims = (200, 80) # (200, 80)
fp_dims = (83.32, 17.6) #50.5)
#fp_dims = (83.32, 17.6) #50.5)
#fp = FloorPlanPlotRec((83.32, 17.16), 20, floorplan_bg_img=img)
# plot_data_heatmap(pipe, floor_plotter=fp)
......@@ -183,23 +204,65 @@ def visualize(p_reg: Pipeline=None, p_circle: Pipeline=None, p_quantile: Pipelin
#y_true = y_true[mask]
#y_pred_box = y_pred_box[mask]
for (train, test) in p_box.data_provider.splits_indices:
fp = FloorPlanPlotRec(fp_dims, 2, floorplan_bg_img=img)
fp.draw_points(p_box.data_provider.labels[train, 0], p_box.data_provider.labels[train, 1], color='g', alpha=0.5)
fp.draw_points(p_box.data_provider.labels[test, 0],
p_box.data_provider.labels[test, 1], color='r',
alpha=0.5)
fp.show_plot()
# for (train, test) in p_box.data_provider.splits_indices:
# fp = FloorPlanPlotRec(fp_dims, 2, floorplan_bg_img=img)
# fp.draw_points(p_box.data_provider.labels[train, 0], p_box.data_provider.labels[train, 1], color='g', alpha=0.5)
# fp.draw_points(p_box.data_provider.labels[test, 0],
# p_box.data_provider.labels[test, 1], color='r',
# alpha=0.5)
# fp.show_plot()
#fp = FloorPlanPlotRec(fp_dims, 2, floorplan_bg_img=img)
fp = FloorPlanPlotRec(fp_dims, 2, floorplan_bg_img=img)
for idx in range(vis_idx[1]-vis_idx[0]):#len(y_true)):
idx += vis_idx[0]
#if np.prod(y_pred_box[idx, 2:]) < 600:
# continue
fp = FloorPlanPlotRec(fp_dims, 2, floorplan_bg_img=img)
fp.draw_points(y_true[idx, 0], y_true[idx, 1], color='g', alpha=0.5)
#fp = FloorPlanPlotRec(fp_dims, 2, floorplan_bg_img=img)
# (train, test) = p_box.data_provider.splits_indices[0]
# fp.draw_points(p_box.data_provider.labels[train, 0],
# p_box.data_provider.labels[train, 1], color='g',
# alpha=0.5)
# fp.draw_points(p_box.data_provider.labels[test, 0],
# p_box.data_provider.labels[test, 1], color='r',
# alpha=0.5)
# plot training data
x_train, y_train = p_box.data_provider.get_train_data()
fp.draw_points(y_train[:, 0], y_train[:, 1], color="red", alpha=0.5)
# # find points that are within box
# lab = p_box.data_provider.labels
#
# x_test_full = None
# for s_idx in range(p_box.data_provider.num_splits):
# x_test, y_test = p_box.data_provider.get_test_data(labels=p_box.data_provider.grid_labels, split_idx=s_idx)
# if x_test_full is not None:
# x_test_full = np.concatenate((x_test_full, x_test), axis=0)
# else:
# x_test_full = x_test
#
# sig_diff_threshold = 2.0
# dat = p_box.data_provider.data_tensor
# x_range = np.logical_and(lab[:, 0] < y_pred_box[idx, 0] + y_pred_box[idx, 2]/2.0,
# lab[:, 0] > y_pred_box[idx, 0] - y_pred_box[idx, 2]/2.0)
# y_range = np.logical_and(lab[:, 1] < y_pred_box[idx, 1] + y_pred_box[idx, 3]/2.0,
# lab[:, 1] > y_pred_box[idx, 1] - y_pred_box[idx, 3]/2.0)
#
# inside_mask = np.where(np.logical_and(x_range, y_range))[0]
# outside_mask = np.where(~np.logical_and(x_range, y_range))[0]
#
# sig_diff = np.linalg.norm(x_test_full - x_test_full[idx, :], axis=1)
# # color with alpha depending on sig_diff
# pred_colors = np.zeros((len(inside_mask), 4))
# # for red the first column needs to be one
# pred_colors[:, 0] = 1.0
# pred_colors[:, 3] = 1 - sig_diff[inside_mask] / sig_diff_threshold
#
# fp.draw_points(lab[inside_mask, 0], lab[inside_mask, 1], color=pred_colors, alpha=None)#, alpha=0.5)
#fp.draw_points(lab[outside_mask, 0], lab[outside_mask, 1], color='black',
# alpha=0.2)
# box_size = y_pred[:]
if p_circle is not None:
......@@ -216,8 +279,9 @@ def visualize(p_reg: Pipeline=None, p_circle: Pipeline=None, p_quantile: Pipelin
fp.draw_rectangles_new(anchors=y_pred_box[idx, :], color='black')
#fp.draw_ellipse(y_pred_box[idx, :2], y_pred_box[idx, 2], y_pred_box[idx, 3], color="r")
fp.draw_points(y_true[idx, 0], y_true[idx, 1], color='g', alpha=0.5)
fp.show_plot()
fp.show_plot()
def transform_quantile_to_bbox(pipe: Pipeline):
......@@ -235,9 +299,50 @@ def transform_quantile_to_bbox(pipe: Pipeline):
pipe.summary.y_pred = summary
def move_pred_closer(pipe: Pipeline, dist=1.0):
p = []
for (y_pred, y_true) in zip(pipe.summary.y_pred, pipe.summary.y_true_labels):
diff = y_pred - y_true
arg_max = np.argmax(np.abs(diff), axis=1)
left_minus = np.where(np.logical_and(arg_max == 0, diff[:, 0] < 0))[0]
left_plus = np.where(np.logical_and(arg_max == 0, diff[:, 0] > 0))[0]
right_minus = np.where(np.logical_and(arg_max == 1, diff[:, 1] < 0))[0]
right_plus = np.where(np.logical_and(arg_max == 1, diff[:, 1] > 0))[0]
y_pred[left_minus] += dist
y_pred[left_plus] -= dist
y_pred[right_minus, 1] += dist
y_pred[right_plus, 1] -= dist
p.append(y_pred)
pipe.summary.y_pred = p
if __name__ == "__main__":
main(p_box_f="../evaluation/gia/evaluation/floor_classifier_v2/output/FLOOR_4_box_up_pred")#_up_pred")
#main(p_box_f="../evaluation/gia/evaluation/floor_classifier_v2/output/FLOOR_4_box_up_pred")#_up_pred")
#p_reg_f="../evaluation/gia/evaluation/floor_classifier_v2/output/FLOOR_1_reg_2")
#p_reg_f="../evaluation/simulation/evaluation/big/output/REG_2")
#main(p_reg_f="../evaluation/lohan/evaluation/new_knn/output/REG_2",
# p_box_f="../evaluation/lohan/evaluation/new_knn/output/BBOX_2")
\ No newline at end of file
# p_box_f="../evaluation/lohan/evaluation/new_knn/output/BBOX_2")
f1 = "/Users/mariuslaska/PycharmProjects/boxprediction/evaluation/lohan/evaluation/new_knn/output/BBOX_2"
f2 = "../evaluation/lohan/evaluation/grid_new_loss/output/BBOX_v2"
reg1 = "/Users/mariuslaska/PycharmProjects/boxprediction/evaluation/lohan/evaluation/new_knn/output/REG_1"
reg2 = "../evaluation/lohan/evaluation/grid_new_loss/output/REG_DEEP"
f = "../evaluation/lohan/evaluation/2layer_grid/output/BBOX"
f1 = "../evaluation/lohan/evaluation/overlap/output/{}".format("BBOX_aug3")
f2 = "../evaluation/lohan/evaluation/grid_new_loss/output/REG_DEEP"
f1 = "../evaluation/UJIndoorLoc/b0/f2/overlap/output/BBOX_no_aug_4"
f2 = "../evaluation/UJIndoorLoc/b0/f2/overlap/output/REG_DEEP"
main(p_box_f=f1,
p_reg_f=f2, vis_idx=(0,77))
\ No newline at end of file
......@@ -30,7 +30,7 @@ def plot():
box_pipe: Pipeline = Storable.load("evaluation/UJIndoorLoc/box/b1/f1/output/BBOX")
point_pipe: Pipeline = Storable.load("evaluation/UJIndoorLoc/box/b1/f1/output/REG")
box_acc, _ = calc_acc_c(np.concatenate(box_pipe.summary.y_true_labels, axis=0), np.concatenate(box_pipe.summary.y_pred, axis=0))
box_acc, _, _ = calc_acc_c(np.concatenate(box_pipe.summary.y_true_labels, axis=0), np.concatenate(box_pipe.summary.y_pred, axis=0))
box_center_error = center_diff(np.concatenate(box_pipe.summary.y_true_labels, axis=0), np.concatenate(box_pipe.summary.y_pred, axis=0))
print(box_acc)
......@@ -70,6 +70,7 @@ def get_avg_box_size(model: Pipeline):
return np.mean(y_pred[:, 2] * y_pred[:, 3])
def find_acc_of_area(model: Pipeline, area):
r = np.sqrt(area/PI)
acc = get_radius_acc(model, r)
......
......@@ -8,12 +8,14 @@ from analysis.evaluate_circle import PI
from analysis.visualize_box_overlap import normalize
import matplotlib.pyplot as plt
from analysis.visualize_learning_progress import convert_from_grid, convert_from_2dim_grid
from analysis.visualize_learning_progress import convert_from_grid, \
convert_from_2dim_grid, convert_from_2dim_overlapping_grid
from base.floor_plan_plot import FloorPlanPlotRec
from analysis.full_visual_cmp import transform_quantile_to_bbox
def main():
p_box: Pipeline = Storable.load("../evaluation/lohan/evaluation/grid_q/output/QUANTILE_2")
p_box: Pipeline = Storable.load("../evaluation/lohan/evaluation/overlap/output/{}".format("BBOX_aug2"))
dp = p_box.data_provider
fp_width = dp.floorplan_width
......@@ -28,8 +30,11 @@ def main():
x_train, y_train = dp.get_train_data(split_idx=split_idx, area_labels=False)
# convert_from_grid(p_box)
convert_from_2dim_grid(p_box, grid_size=40, quantile=True)
transform_quantile_to_bbox(p_box)
#convert_from_2dim_grid(p_box, grid_size=40, quantile=True)
#transform_quantile_to_bbox(p_box)
convert_from_2dim_overlapping_grid(p_box, grid_size=40, quantile=False,
store=True,
average_samples=True)
y_pred = p_box.summary.y_pred[
split_idx] # np.concatenate(p_box.summary.y_pred[split_idx], axis=0)
......
......@@ -25,7 +25,7 @@ def main():
y_true = np.concatenate(pipe.summary.y_true_labels, axis=0)
y_pred = np.concatenate(pipe.summary.y_pred, axis=0)
acc, wrong_mask = calc_acc_c(y_true, y_pred)
acc, wrong_mask, _ = calc_acc_c(y_true, y_pred)
print("acc: {}".format(acc))
print("center-dist: {}".format(center_diff(y_true, y_pred)))
print("avg_center: {}".format(np.mean(y_pred[:, :2], axis=0)))
......
......@@ -85,6 +85,282 @@ def main():
fp.show_plot()
def convert_from_2dim_2layer_grid(pipe: Pipeline, grid_size=20, quantile=False, store=True, average_samples=True):
n_cols = math.ceil(pipe.data_provider.floorplan_width / grid_size)
res_folds = []
height = pipe.data_provider.floorplan_height
width = pipe.data_provider.floorplan_width
# Determine #row,col for 1st layer
num_row_l1 = np.ceil(height / grid_size)
num_col_l1 = np.ceil(width / grid_size)
num_l1 = int(num_row_l1 * num_col_l1)
num_row_l2 = num_row_l1 - 1
num_col_l2 = num_col_l1 - 1
num_l2 = int(num_row_l2 * num_col_l2)
num = num_l1 + num_l2
origins = []
# Determine centers & origins (lower-left)
for idx in range(num):
# check whether 1st or 2nd layer
if idx < num_l1:
# 1st layer
r_idx = int(idx / num_col_l1)
c_idx = idx % num_col_l1
x = c_idx * grid_size
y = r_idx * grid_size
origins.append(np.array([x, y]))
else:
# 2nd layer
idx -= num_l1
r_idx = int(idx / num_col_l2)
c_idx = idx % num_col_l2
x = c_idx * grid_size
y = r_idx * grid_size