Commit a2e1b16e authored by Marius Laska's avatar Marius Laska

added support for ujiindoor loc dataset

parent 57827030
......@@ -14,42 +14,36 @@ from analysis.visualize_learning_progress import convert_from_grid
def main():
#pipe_c: Pipeline = Storable.load("evaluation/gia/cmp/output/CIRCLE")
pipe_c: Pipeline = Storable.load("../evaluation/lohan/evaluation/grid/output/BBOX_NEW")
#pipe_c: Pipeline = Storable.load("evaluation/lohan/full_cmp/output/QUANTILE")
#pipe_c: Pipeline = Storable.load("evaluation/lohan/full_cmp/output/QUANTILE")
pipe_r: Pipeline = Storable.load("../evaluation/lohan/evaluation/grid/output/REG")
pipe_c: Pipeline = Storable.load("../evaluation/lohan/evaluation/deep/output/BBOX_NEW")
convert_from_grid(pipe_c)
# for fold_idx in range(pipe_c.data_provider.num_splits):
# pipe_c.summary.y_true_labels[fold_idx][:, 0] = 200 - \
# pipe_c.summary.y_true_labels[
# fold_idx][:, 0]
# pipe_c.summary.y_true_labels[fold_idx][:, 1] = 80 - \
# pipe_c.summary.y_true_labels[
# fold_idx][:, 1]
# pipe_c.summary.y_pred[fold_idx][:, 0] = 200 - \
# pipe_c.summary.y_pred[
# fold_idx][:, 0]
# pipe_c.summary.y_pred[fold_idx][:, 1] = 80 - \
# pipe_c.summary.y_pred[
# fold_idx][:, 1]
#y_pred = np.concatenate(pipe_r.summary.y_pred, axis=0)
#y_true = np.concatenate(pipe_r.summary.y_true_labels, axis=0)
y_pred = np.concatenate(pipe_c.summary.y_pred, axis=0)[:, :2]
y_pred_box_shape = np.concatenate(pipe_c.summary.y_pred, axis=0)[:, 2:]
y_true = np.concatenate(pipe_c.summary.y_true_labels, axis=0)
#y_pred_reg = np.concatenate(pipe_r.summary.y_pred, axis=0)
error = np.linalg.norm(y_pred - y_true, axis=1)
sub_mask = np.where(error < 60)[0]
error = error[sub_mask]
# x/y error
x_y_error = np.abs(y_pred[:, 0] - y_true[:, 0]) / np.abs(y_pred[:, 1] - y_true[:, 1])
x_y_error[x_y_error < 1] = -1
x_y_error[x_y_error >= 1] = 1
w_h_error = y_pred_box_shape[:, 0]/y_pred_box_shape[:, 1]
w_h_error[w_h_error < 1] = -1
w_h_error[w_h_error >= 1] = 1
r = len(np.where(x_y_error == w_h_error)[0]) / len(x_y_error)
circle_size = np.prod(np.concatenate(pipe_c.summary.y_pred, axis=0)[:, 2:], axis=1)
#error = x_y_error
#circle_size = w_h_error
sub_mask = np.where(error < 200)[0]
error = error[sub_mask]
#circle_size = get_size_for_quantile(pipe_c)
circle_size = circle_size[sub_mask]
......@@ -79,7 +73,7 @@ def main():
sns.kdeplot(error, circle_size, shade = True, cmap = "PuBu")
plt.show()
img = "evaluation/gia/gia_floor_4.jpg"
img = "../evaluation/gia/gia_floor_4.jpg"
img = resource_filename('data', 'lohan/CrowdsourcedDS1floor.png')
fp_dims = (83.32, 17.16)
fp_dims = (200, 80)
......
......@@ -10,24 +10,27 @@ from analysis.evaluate_circle import get_success_rate, get_avg_circle_size, \
from analysis.visualize_learning_progress import convert_from_grid, \
convert_from_2dim_grid
from base.floor_plan_plot import FloorPlanPlotRec
from main import calc_acc_c, center_diff
from analysis.plot_analysis import find_radius_for_acc, get_avg_box_size
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
PI = 3.14159265359
def main():
def main(idx):
p_reg: Pipeline = Storable.load("../evaluation/lohan/evaluation/grid/output/REG")
p_circle: Pipeline = None#Storable.load("evaluation/lohan/full_cmp/output/CIRCLE")
p_quantile: Pipeline = None#Storable.load("evaluation/lohan/full_cmp/output/QUANTILE")
p_box: Pipeline = Storable.load("../evaluation/lohan/evaluation/grid/output/BBOX_NEW")#"evaluation/lohan/scaled_output_2/output/BBOX") # Storable.load("evaluation/gia/full_cmp/output/BBOX")
p_reg: Pipeline = None #Storable.load("evaluation/lohan/evaluation/final/output/REG_{}".format(idx))
p_circle: Pipeline = None #Storable.load("evaluation/lohan/full_cmp/output/CIRCLE")
p_quantile: Pipeline = None #Storable.load("evaluation/lohan/full_cmp/output/QUANTILE")
p_box: Pipeline = Storable.load("/Users/mariuslaska/Dropbox/BBOX_{}".format(idx)) # Storable.load("evaluation/lohan/evaluation/final/output/BBOX_{}".format(idx)) #Storable.load("../evaluation/UJIndoorLoc/grid/output/BBOX")##"evaluation/lohan/scaled_output_2/output/BBOX") # Storable.load("evaluation/gia/full_cmp/output/BBOX")
fp_dims = (83.32, 17.16)
fp_dims = (p_box.data_provider.floorplan_width, p_box.data_provider.floorplan_height)
convert_from_2dim_grid(p_box, grid_size=40)
#convert_from_grid(p_box)
#convert_from_2dim_grid(p_box, grid_size=20)
convert_from_grid(p_box)
#p_box.summary.y_pred = [p_box.summary.y_pred[idx]]
#p_box.summary.y_true_labels = [p_box.summary.y_true_labels[idx]]
# for fold_idx in range(p_box.data_provider.num_splits):
# p_box.summary.y_true_labels[fold_idx][:, 0] *= fp_dims[0]
......@@ -81,10 +84,14 @@ def main():
y_pred = np.concatenate(p_box.summary.y_pred, axis=0)
acc_box, wrong_mask = calc_acc_c(y_true, y_pred)
#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)
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(get_avg_box_size(p_box)))
print("avg_box_size: {}".format(b_size))
dist = get_dist_from_box(p_box)
print("DEVIATION: {}".format(dist))
......@@ -112,19 +119,23 @@ def main():
# comparison to REG
#radius_c = find_radius_for_acc(p_reg, accuracy=success)
#print("SIZE_REG (CIRCLE): {}".format(PI * math.pow(radius_c, 2)))
radius_b = find_radius_for_acc(p_reg, accuracy=acc_box)
#acc_b = find_acc_of_area(p_reg, area=b_size)
print("SIZE_REG (BOX): {}".format(PI * math.pow(radius_b, 2)))
#print("ACC_REG (BOX): {}".format(acc_b))
#radius_b = find_radius_for_acc(p_reg, accuracy=acc_quantile)
#print("SIZE_REG (QUANTILE): {}".format(PI * math.pow(radius_b, 2)))
visualize(p_reg, p_circle, p_quantile, p_box)
radius_b = 0
visualize(p_reg, p_circle, p_quantile, p_box, radius_b)
def visualize(p_reg: Pipeline=None, p_circle: Pipeline=None, p_quantile: Pipeline=None, p_box: Pipeline=None):
#img = "../evaluation/gia/gia_floor_4.jpg"
#fp_dims = (83.32, 17.16)
img = resource_filename('data', 'lohan/CrowdsourcedDS1floor.png')
fp_dims = (200, 80)
def visualize(p_reg: Pipeline=None, p_circle: Pipeline=None, p_quantile: Pipeline=None, p_box: Pipeline=None, radius=9.0):
img = "../evaluation/gia/gia_floor_4.jpg"
fp_dims = (83.32, 17.16)
#img = resource_filename('data', 'lohan/CrowdsourcedDS1floor.png')
#fp_dims = (200, 80)
#fp = FloorPlanPlotRec((83.32, 17.16), 20, floorplan_bg_img=img)
# plot_data_heatmap(pipe, floor_plotter=fp)
if p_reg is not None:
......@@ -149,36 +160,40 @@ 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()
fp = FloorPlanPlotRec(fp_dims, 2, floorplan_bg_img=img)
for idx in range(50):#len(y_true)):
idx += 0
#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)
# box_size = y_pred[:]
if p_circle is not None:
fp.draw_circles(centers=y_pred_circle[idx, :2], radius=y_pred_circle[idx, 2], color='r')
if p_reg is not None:
fp.draw_circles(centers=y_pred_reg[idx, :2], radius=12.506, color='b')
if p_quantile is not None:
fp.draw_points(y_pred_quantile[idx, 0], y_pred_quantile[idx, 1], color="r")
fp.draw_points(y_pred_quantile[idx, 2], y_pred_quantile[idx, 3],
color="b")
fp.draw_rectangles(anchors=y_pred_quantile[idx, :], color="g")
if p_box is not None:
fp.draw_rectangles_new(anchors=y_pred_box[idx, :], color='black')
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)
# for idx in range(50):#len(y_true)):
# #idx += 150
# #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)
#
# # box_size = y_pred[:]
# if p_circle is not None:
# fp.draw_circles(centers=y_pred_circle[idx, :2], radius=y_pred_circle[idx, 2], color='r')
# if p_reg is not None:
# fp.draw_circles(centers=y_pred_reg[idx, :2], radius=radius, color='b')
# if p_quantile is not None:
# fp.draw_points(y_pred_quantile[idx, 0], y_pred_quantile[idx, 1], color="r")
# fp.draw_points(y_pred_quantile[idx, 2], y_pred_quantile[idx, 3],
# color="b")
#
# fp.draw_rectangles(anchors=y_pred_quantile[idx, :], color="g")
# if p_box is not None:
# 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.show_plot()
if __name__ == "__main__":
main()
\ No newline at end of file
for idx in range(1):
main(idx+1)
\ No newline at end of file
......@@ -70,6 +70,11 @@ 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)
return acc
def find_radius_for_acc(model: Pipeline, step_size=.0001, accuracy=1):
acc = 0
......
from il_pipeline.pipeline import Pipeline
from il_pipeline.utility.storable import Storable
import numpy as np
from pkg_resources import resource_filename
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
from base.floor_plan_plot import FloorPlanPlotRec
def main():
p_box: Pipeline = Storable.load("../evaluation/lohan/evaluation/deep/output/BBOX_NEW")
p_reg: Pipeline = Storable.load("../evaluation/lohan/evaluation/deep/output/REG")
dp = p_box.data_provider
fp_width = dp.floorplan_width
fp_height = dp.floorplan_height
split_idx = 1
radius = 10.069
x_test, y_true = dp.get_test_data(split_idx=split_idx, area_labels=False)
x_train, y_train = dp.get_train_data(split_idx=split_idx, area_labels=False)
convert_from_grid(p_box)
y_pred = p_box.summary.y_pred[split_idx]#np.concatenate(p_box.summary.y_pred[split_idx], axis=0)
y_pred_reg = p_reg.summary.y_pred[split_idx]
#y_true = np.concatenate(p_box.summary.y_true[split_idx], axis=0)
# get test point
idx = 0
g_size = 6
size = np.prod(y_pred[:, 2:], axis=1)
mask = np.where(size * 0.7 > radius**2 * PI)[0]
for idx in mask:
# idx += 50
draw(fp_width, fp_height, g_size, x_test, y_true, x_train, y_train, y_pred, y_pred_reg, idx)
print("test")
def draw(fp_width, fp_height, g_size, x_test, y_true, x_train, y_train, y_pred_box, y_pred_reg, idx=0):
num_g_x = int(fp_width / g_size)
num_g_y = int(fp_height / g_size)
overlap_count = np.full((num_g_y, num_g_x), np.nan)
for y_idx in range(num_g_y):
for x_idx in range(num_g_x):
lower_left = np.array([x_idx * g_size, (y_idx) * g_size])
upper_right = np.array([(x_idx + 1) * g_size, (y_idx + 1) * g_size])
error_diff(y_true, y_pred_box, lower_left, upper_right, threshold=5)
error = error_grid(x_test[idx], x_train, y_train, lower_left,
upper_right)
overlap_count[num_g_y - y_idx - 1, x_idx] = error
overlap_count, norm_overlap_count = normalize(overlap_count, min=1, max=255)
# colormap
cmap = plt.cm.jet # define the colormap
# extract all colors from the .jet map
cmaplist = [cmap(i) for i in range(cmap.N)]
# force the first color entry to be grey
cmaplist[0] = (.5, .5, .5, 0.1)
# Get the colormap colors
my_cmap = cmap(np.arange(cmap.N))
# Set alpha
my_cmap[:, -1] = 0.8
my_cmap[0] = (.75, .75, .75, 0.8)
img = "../evaluation/gia/gia_floor_4.jpg"
#img = resource_filename('data', 'lohan/CrowdsourcedDS1floor.png')
fp_dims = (83.32, 17.16)
#fp_dims = (200, 80)
fp = FloorPlanPlotRec(fp_dims, 20, floorplan_bg_img=img, title="Error")
for y_idx in range(num_g_y):
for x_idx in range(num_g_x):
lower_left = np.array([x_idx * g_size, (y_idx) * g_size])
upper_right = np.array([(x_idx + 1) * g_size, (y_idx + 1) * g_size])
count = overlap_count[num_g_y - y_idx - 1, x_idx]
fp.draw_rectangles(np.concatenate((lower_left, upper_right)),
color=my_cmap[int(count)], fill=True)
fp.draw_circles(centers=y_pred_reg[idx, :2], radius=10.069,
color='b')
fp.draw_points(y_true[idx, 0], y_true[idx, 1], color="green")
fp.draw_rectangles_new(anchors=y_pred_box[idx, :], color='black')
plt.show()
def error_diff(y_true, y_pred, lower_left, upper_right, threshold=5):
min_x = lower_left[0]
min_y = lower_left[1]
max_x = upper_right[0]
max_y = upper_right[1]
x_range = np.logical_and(y_true[:, 0] <= max_x, y_true[:, 0] >= min_x)
y_range = np.logical_and(y_true[:, 1] <= max_y, y_true[:, 1] >= min_y)
f_range = np.logical_and(x_range, y_range)
# get subset that where target value is inside of grid cell
g_mask = np.where(f_range)[0]
if len(g_mask) < 3:
return
center_diff = np.full((len(g_mask), len(g_mask)), np.inf)
for i in range(len(g_mask)):
for j in range(len(g_mask)):
if j>i:
val = np.linalg.norm(y_pred[g_mask[i]] - y_pred[g_mask[j]])
center_diff[i, j] = val
#center_diff[j, i] = val
# get subset where predicted
s_mask = np.where(center_diff < threshold)
if len(s_mask[0]) < 1:
return
s_diff_sum = 0
for i, j in zip(*s_mask):
box_i = y_pred[g_mask[i], 2:]
box_j = y_pred[g_mask[j], 2:]
s_diff_sum += np.linalg.norm(box_i - box_j)
s_diff_avg = s_diff_sum / len(s_mask[0])
if s_diff_avg > 4:
print(s_diff_avg)
def error_grid(x_ref, x, y, lower_left, upper_right):#y_pred, y_true, y_pred_reg, lower_left, upper_right):
min_x = lower_left[0]
min_y = lower_left[1]
max_x = upper_right[0]
max_y = upper_right[1]
x_range = np.logical_and(y[:, 0] <= max_x, y[:, 0] >= min_x)
y_range = np.logical_and(y[:, 1] <= max_y, y[:, 1] >= min_y)
range = np.logical_and(x_range, y_range)
mask = np.where(range)[0]
if len(mask) < 1:
return np.nan
diff = np.linalg.norm(x[mask] - x_ref, axis=1)
return np.mean(diff)
if __name__ == "__main__":
main()
\ No newline at end of file
......@@ -3,6 +3,8 @@ from il_pipeline.utility.storable import Storable
import numpy as np
from mpl_toolkits.axes_grid1 import make_axes_locatable
from pkg_resources import resource_filename
from sklearn import linear_model
from sklearn.metrics import mean_squared_error, r2_score
from analysis.visualize_learning_progress import convert_from_2dim_grid, convert_from_grid
......@@ -21,7 +23,7 @@ def plot_mean_error_per_grid(pipe: Pipeline):
dp = pipe.data_provider
fp_height = dp.floorplan_height
fp_width = dp.floorplan_width
g_size = 12
g_size = 4
y_pred = np.concatenate(pipe.summary.y_pred, axis=0)
y_true = np.concatenate(pipe.summary.y_true_labels, axis=0)
......@@ -29,7 +31,7 @@ def plot_mean_error_per_grid(pipe: Pipeline):
y_pred_reg = np.concatenate(p_c.summary.y_pred, axis=0)
error = np.linalg.norm(y_pred_reg[:, :2] - y_true, axis=1)
mask = np.where(error <= 15)[0] #np.logical_and(error <= 10, y_true[:, 0] >= 40))[0]
mask = np.where(error <= 60)[0] #np.logical_and(error <= 10, y_true[:, 0] >= 40))[0]
y_true = y_true[mask]
y_pred = y_pred[mask]
y_pred_reg = y_pred_reg[mask]
......@@ -42,6 +44,8 @@ def plot_mean_error_per_grid(pipe: Pipeline):
succ_rate = np.full((num_g_y, num_g_x), np.nan)
num_grid = np.full((num_g_y, num_g_x), np.nan)
std_size_grid = np.full((num_g_y, num_g_x), np.nan)
r_score_grid = np.full((num_g_y, num_g_x), np.nan)
r_coeff_grid = np.full((num_g_y, num_g_x), np.nan)
for y_idx in range(num_g_y):
for x_idx in range(num_g_x):
......@@ -49,13 +53,15 @@ def plot_mean_error_per_grid(pipe: Pipeline):
upper_right = np.array([(x_idx + 1) * g_size, (y_idx + 1) * g_size])
# get average error per grid
error, size, size_std, succ = error_grid(y_pred, y_true, y_pred_reg, lower_left, upper_right)
error, size, size_std, r_score, r_coeff, succ = error_grid(y_pred, y_true, y_pred_reg, lower_left, upper_right)
num = get_num_grid(y_pred, y_true, y_pred_reg, lower_left, upper_right)
overlap_count[num_g_y - y_idx - 1, x_idx] = error
pred_size[num_g_y - y_idx - 1, x_idx] = size #avg_box_size_grid(y_pred, lower_left, upper_right)
succ_rate[num_g_y - y_idx - 1, x_idx] = succ
num_grid[num_g_y - y_idx - 1, x_idx] = num
std_size_grid[num_g_y - y_idx - 1, x_idx] = size_std
r_score_grid[num_g_y - y_idx - 1, x_idx] = r_score
r_coeff_grid[num_g_y - y_idx - 1, x_idx] = r_coeff
# scale since size grows quadratically
#
......@@ -66,6 +72,8 @@ def plot_mean_error_per_grid(pipe: Pipeline):
succ_rate, norm_succ_rate = normalize(succ_rate, min=1, max=255)
num_grid, norm_num_grid = normalize(num_grid, min=0, max=255)
std_size_grid, norm_std_size_grid = normalize(std_size_grid, min=0, max=255)
r_score_grid, norm_r_score_grid = normalize(r_score_grid, min=1, max= 255)
r_coeff_grid, norm_r_coeff_grid = normalize(r_coeff_grid, min=1, max=255)
# colormap
cmap = plt.cm.jet # define the colormap
......@@ -81,19 +89,22 @@ def plot_mean_error_per_grid(pipe: Pipeline):
my_cmap[:, -1] = 0.8
my_cmap[0] = (.75, .75, .75, 0.8)
#img = "../evaluation/gia/gia_floor_4.jpg"
img = resource_filename('data', 'lohan/CrowdsourcedDS1floor.png')
#fp_dims = (83.32, 17.16)
fp_dims = (200, 80)
img = "../evaluation/gia/gia_floor_4.jpg"
#img = resource_filename('data', 'lohan/CrowdsourcedDS1floor.png')
fp_dims = (83.32, 17.16)
#fp_dims = (200, 80)
fp = FloorPlanPlotRec(fp_dims, 20, floorplan_bg_img=img, title="Error")
fp_size = FloorPlanPlotRec(fp_dims, 20, floorplan_bg_img=img, title="BoxSize")
fp_succ = FloorPlanPlotRec(fp_dims, 20, floorplan_bg_img=img, title="ACC")
fp_num = FloorPlanPlotRec(fp_dims, 20, floorplan_bg_img=img, title="#Test")
fp_size_std = FloorPlanPlotRec(fp_dims, 20, floorplan_bg_img=img, title="BoxSizeSTD")
fp_r_score = FloorPlanPlotRec(fp_dims, 20, floorplan_bg_img=img, title="R-score")
fp_r_coeff = FloorPlanPlotRec(fp_dims, 20, floorplan_bg_img=img,
title="R-coeff")
plots = [fp, fp_size, fp_succ, fp_num, fp_size_std]
norms = [norm_overlap_count, norm_pred_size, norm_succ_rate, norm_num_grid, norm_std_size_grid]
plots = [fp, fp_size, fp_succ, fp_num, fp_size_std, fp_r_score, fp_r_coeff]
norms = [norm_overlap_count, norm_pred_size, norm_succ_rate, norm_num_grid, norm_std_size_grid, norm_r_score_grid, norm_r_coeff_grid]
for y_idx in range(num_g_y):
for x_idx in range(num_g_x):
......@@ -105,6 +116,8 @@ def plot_mean_error_per_grid(pipe: Pipeline):
succ = succ_rate[num_g_y - y_idx - 1, x_idx]
num = num_grid[num_g_y - y_idx - 1, x_idx]
s_std = std_size_grid[num_g_y - y_idx - 1, x_idx]
r_score = r_score_grid[num_g_y - y_idx - 1, x_idx]
r_coeff = r_coeff_grid[num_g_y - y_idx - 1, x_idx]
fp.draw_rectangles(np.concatenate((lower_left, upper_right)),
color=my_cmap[int(count)], fill=True)
......@@ -116,6 +129,12 @@ def plot_mean_error_per_grid(pipe: Pipeline):
color=my_cmap[int(num)], fill=True)
fp_size_std.draw_rectangles(np.concatenate((lower_left, upper_right)),
color=my_cmap[int(s_std)], fill=True)
fp_r_score.draw_rectangles(
np.concatenate((lower_left, upper_right)),
color=my_cmap[int(r_score)], fill=True)
fp_r_coeff.draw_rectangles(
np.concatenate((lower_left, upper_right)),
color=my_cmap[int(r_coeff)], fill=True)
for p,n in zip(plots, norms):
add_colorbar(p, cmap, n)
......@@ -166,10 +185,10 @@ def main():
# Set alpha
my_cmap[:, -1] = np.linspace(0, 1, cmap.N)
img = "evaluation/gia/gia_floor_4.jpg"
#img = resource_filename('data', 'lohan/CrowdsourcedDS1floor.png')
fp_dims = (83.32, 17.16)
#fp_dims = (200, 80)
#img = "evaluation/gia/gia_floor_4.jpg"
img = resource_filename('data', 'lohan/CrowdsourcedDS1floor.png')
#fp_dims = (83.32, 17.16)
fp_dims = (200, 80)
fp = FloorPlanPlotRec(fp_dims, 20, floorplan_bg_img=img)
for y_idx in range(num_g_y):
......@@ -238,7 +257,7 @@ def error_grid(y_pred, y_true, y_pred_reg, lower_left, upper_right):
mask = np.where(range)[0]
if len(mask) < 10:
return np.nan, np.nan, np.nan, np.nan
return np.nan, np.nan, np.nan, np.nan, np.nan, np.nan
#size = np.abs(y_pred[mask, 0] - y_pred[mask, 2]) * np.abs(y_pred[mask, 1] - y_pred[mask, 3])
......@@ -253,7 +272,32 @@ def error_grid(y_pred, y_true, y_pred_reg, lower_left, upper_right):
size = np.prod(y_pred[mask, 2:], axis=1)
diff = np.linalg.norm(y_true[mask] - y_pred_reg[mask, :2], axis=1)
return np.mean(diff), np.mean(size), np.std(size), len(correct)/len(mask)
regr = linear_model.LinearRegression()
# Train the model using the training sets
regr.fit(diff.reshape(-1, 1), size.reshape(-1, 1))
# Make predictions using the testing set
y_val = regr.predict(diff.reshape(-1, 1))
r_score = r2_score(size, y_val)
if r_score > 0.2:
plt.scatter(diff, size)
plt.plot(diff, y_val)
# The coefficients
print('Coefficients: \n', regr.coef_)
# The mean squared error
print('Mean squared error: %.2f'
% mean_squared_error(size, y_val))
# The coefficient of determination: 1 is perfect prediction
print('Coefficient of determination: %.2f'
% r_score)
plt.show()
return np.mean(diff), np.mean(size), np.std(size), r_score, regr.coef_[0][0], len(correct)/len(mask)
def overlap_reg(y_pred, radius, lower_left, upper_right):
......@@ -324,6 +368,6 @@ if __name__ == "__main__":
for id in [128]:
pipe: Pipeline = Storable.load(
"../evaluation/lohan/evaluation/grid/output/BBOX_NEW")#{}".format(id))
"../evaluation/gia/evaluation/grid/output/BBOX_2")#{}".format(id))
plot_mean_error_per_grid(pipe)
\ No newline at end of file
......@@ -127,7 +127,7 @@ class BboxModel(DnnModel):