Commit 57827030 authored by Marius Laska's avatar Marius Laska

main ready for batch mode

parent ba09fcce
......@@ -15,7 +15,7 @@ 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")
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")
......@@ -41,8 +41,7 @@ def main():
y_pred = 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)
#y_pred_reg = np.concatenate(pipe_r.summary.y_pred, axis=0)
error = np.linalg.norm(y_pred - y_true, axis=1)
......
......@@ -19,7 +19,7 @@ PI = 3.14159265359
def main():
p_reg: Pipeline = None # Storable.load("../evaluation/lohan/evaluation/grid/output/REG")
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")
......
from il_pipeline.pipeline import Pipeline
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 analysis.visualize_learning_progress import convert_from_2dim_grid, convert_from_grid
import matplotlib.pyplot as plt
import matplotlib as mpl
from base.floor_plan_plot import FloorPlanPlotRec
def plot_mean_error_per_grid(pipe: Pipeline):
#pipe: Pipeline = Storable.load("evaluation/lohan/full_cmp/output/BBOX")
#pipe: Pipeline = Storable.load("evaluation/lohan/progress/output/BBOX_1")
p_c = pipe #Storable.load("../evaluation/lohan/evaluation/grid/output/REG")
fp_dims = (83.32, 17.16)
p_c = pipe
convert_from_grid(pipe)
# for fold_idx in range(pipe.data_provider.num_splits):
# pipe.summary.y_true_labels[fold_idx][:, 0] *= fp_dims[0]
# pipe.summary.y_true_labels[fold_idx][:, 1] *= fp_dims[0]
#
# pipe.summary.y_pred[fold_idx][:, [0, 2]] *= fp_dims[0]
# pipe.summary.y_pred[fold_idx][:, [1, 3]] *= fp_dims[0]
radius = 5
dp = pipe.data_provider
fp_height = dp.floorplan_height
fp_width = dp.floorplan_width
......@@ -38,8 +26,6 @@ def plot_mean_error_per_grid(pipe: Pipeline):
y_pred = np.concatenate(pipe.summary.y_pred, axis=0)
y_true = np.concatenate(pipe.summary.y_true_labels, axis=0)
#y_pred[:, 2:] = np.abs(y_pred[:, 2:])
y_pred_reg = np.concatenate(p_c.summary.y_pred, axis=0)
error = np.linalg.norm(y_pred_reg[:, :2] - y_true, axis=1)
......@@ -71,28 +57,15 @@ def plot_mean_error_per_grid(pipe: Pipeline):
num_grid[num_g_y - y_idx - 1, x_idx] = num
std_size_grid[num_g_y - y_idx - 1, x_idx] = size_std
overlap_count = (((overlap_count - np.nanmin(overlap_count)) * (255 - 1)) / (
np.nanmax(overlap_count) - np.nanmin(overlap_count))) + 1
overlap_count[np.where(np.isnan(overlap_count))] = 0
# scale since size grows quadratically
#
pred_size = np.sqrt(pred_size/2)
pred_size = (((pred_size - np.nanmin(pred_size)) * (255 - 1)) / (
np.nanmax(pred_size) - np.nanmin(pred_size))) + 1
pred_size[np.where(np.isnan(pred_size))] = 0
succ_rate = (((succ_rate - np.nanmin(succ_rate)) * (
255 - 1)) / (np.nanmax(succ_rate) - np.nanmin(succ_rate))) + 1
succ_rate[np.where(np.isnan(succ_rate))] = 0
num_grid = (((num_grid - np.nanmin(num_grid)) * (
255 - 0)) / (np.nanmax(num_grid) - np.nanmin(num_grid))) + 0
succ_rate[np.where(np.isnan(num_grid))] = 0
std_size_grid = (((std_size_grid - np.nanmin(std_size_grid)) * (
255 - 0)) / (np.nanmax(std_size_grid) - np.nanmin(std_size_grid))) + 0
std_size_grid[np.where(np.isnan(std_size_grid))] = 0
# normalize between 0 and 255 to match cmap values
overlap_count, norm_overlap_count = normalize(overlap_count, min=1, max=255)
pred_size, norm_pred_size = normalize(pred_size, min=1, max=255)
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)
# colormap
cmap = plt.cm.jet # define the colormap
......@@ -118,6 +91,10 @@ def plot_mean_error_per_grid(pipe: Pipeline):
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")
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]
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])
......@@ -140,6 +117,8 @@ def plot_mean_error_per_grid(pipe: Pipeline):
fp_size_std.draw_rectangles(np.concatenate((lower_left, upper_right)),
color=my_cmap[int(s_std)], fill=True)
for p,n in zip(plots, norms):
add_colorbar(p, cmap, n)
fp.show_plot()
......@@ -258,7 +237,7 @@ def error_grid(y_pred, y_true, y_pred_reg, lower_left, upper_right):
mask = np.where(range)[0]
if len(mask) < 5:
if len(mask) < 10:
return 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])
......@@ -298,6 +277,26 @@ def overlap_reg(y_pred, radius, lower_left, upper_right):
return len(np.where(mask)[0])
def add_colorbar(fp, cmap, norm):
divider = make_axes_locatable(fp.axis)
ax_cb = divider.new_horizontal(size="5%", pad=0.15)
cb1 = mpl.colorbar.ColorbarBase(ax_cb, cmap=cmap,
norm=norm,
orientation='vertical')
fp.fig.add_axes(ax_cb)
def normalize(x, min=1, max=255, nan_val=0):
norm = mpl.colors.Normalize(vmin=np.nanmin(x),
vmax=np.nanmax(x))
x = (((x - np.nanmin(x)) * (max - min)) / (
np.nanmax(x) - np.nanmin(x))) + min
x[np.where(np.isnan(x))] = nan_val
return x, norm
def overlap(y_pred, lower_left, upper_right):
centers = y_pred[:, :2]
widths = y_pred[:, 2]
......
import argparse
import copy
import logging
......@@ -159,23 +160,8 @@ def execute(conf_file):
#data_provider.labels[:, 1] /= data_provider.floorplan_height
# compute grid encoding
data_provider.transform_to_grid_encoding()
#data_provider.transform_to_2dim_grid_encoding(grid_size=20)
# reverse labels
#center = np.median(data_provider.labels, axis=0)
#data_provider.labels[:] = data_provider.labels - center
#data_provider.labels[:, 0] = 200 - data_provider.labels[:, 0]
#data_provider.labels[:, 1] = 80 - data_provider.labels[:, 1]
# else:
# log.error("'type' parameter of 'floor_plan' should be "
# "(regression or segmentation), but was {} instead".
# format(fp_params['type']))
#fp.draw_points(data_provider)
if "GRID" in model_params['type']:
data_provider.transform_to_grid_encoding()
pipeline = BboxPipeline(data_provider,
clusterer,
......@@ -194,12 +180,13 @@ def execute(conf_file):
def main():
file = "gia_evaluation.yml"
file = "ujiindoor_circle.yml"
#file = "config_lohan.yml"
file = "config/lohan_deep.yml"
execute(file)
#point_uncertainty_estimation(file, "evaluation/lohan/old_loss/progress/output/BBOX_256_base.hdf5")
parser = argparse.ArgumentParser()
parser.add_argument("-c", help="Path to yml config file")
args = parser.parse_args()
execute(args.c)
def illustrate_results(file):
pipe: BboxPipeline = Storable.load(file)
......
......@@ -160,13 +160,11 @@ def train_model(params, pipe: BboxPipeline, exp_number, downsample):
def report():
r = ta.Reporting("indoor_loc_2.csv")
r = ta.Reporting("/Users/mariuslaska/Dropbox/PhD/BboxPaper/files/regression_1.csv")
data = r.data
test = data.sort_values(by=['val_loss'], ascending=True).head(5)
test = r.best_params(metric="val_loss")
r.plot_corr(metric="val_loss")
print(test)
......@@ -187,5 +185,5 @@ def main():
if __name__ == "__main__":
#report()
main()
\ No newline at end of file
report()
#main()
\ No newline at end of file
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