Commit 9076770a authored by Marius Laska's avatar Marius Laska

grid encoding customizable via pipeline parameters (.yml file)

parent a2e1b16e
......@@ -19,10 +19,10 @@ PI = 3.14159265359
def main(idx):
p_reg: Pipeline = None #Storable.load("evaluation/lohan/evaluation/final/output/REG_{}".format(idx))
p_reg: Pipeline = Storable.load("../evaluation/UJIndoorLoc/grid_test/output/REG") #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")
p_box: Pipeline = Storable.load("../evaluation/UJIndoorLoc/grid_test/output/BBOX") #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 = (p_box.data_provider.floorplan_width, p_box.data_provider.floorplan_height)
......@@ -127,7 +127,7 @@ def main(idx):
#radius_b = find_radius_for_acc(p_reg, accuracy=acc_quantile)
#print("SIZE_REG (QUANTILE): {}".format(PI * math.pow(radius_b, 2)))
radius_b = 0
#radius_b = 0
visualize(p_reg, p_circle, p_quantile, p_box, radius_b)
......@@ -160,38 +160,38 @@ 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 += 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()
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(len(y_true)):#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__":
......
......@@ -106,14 +106,14 @@ class BboxModel(DnnModel):
def setup_model(self, setup_params=False):
# use instance variables if no optional variables are supplied
output_dir = self.output_dir
data_provider = self.data_provider
dp = self.data_provider
params = self.params
if setup_params:
self.setup_params()
# obtain Keras classifier (Sequential) for specified parameters
x_cols, y_cols = data_provider.get_data_dims("regression") # was regression
x_cols, y_cols = dp.get_data_dims("regression") # was regression
if self.type == "regression":
y_cols = 2
if self.type == "BBOX":
......@@ -125,9 +125,16 @@ class BboxModel(DnnModel):
if self.type == "S_Q":
y_cols = 1
if self.type == "GRID-BBOX":
ma = max(data_provider.floorplan_width, data_provider.floorplan_height)
mi = min(data_provider.floorplan_width, data_provider.floorplan_height)
y_cols = 5 * 10#math.ceil(ma/mi)
if dp.grid_size is None:
# single row or column encoding
ma = max(dp.floorplan_width, dp.floorplan_height)
mi = min(dp.floorplan_width, dp.floorplan_height)
y_cols = 5 * math.ceil(ma/mi)
else:
# grid encoding with fixed grid size
y_cols = 5 * math.ceil(
dp.floorplan_height / dp.grid_size) * math.ceil(
dp.floorplan_width / dp.grid_size)
# obtain the model definition
if "BBOX" in self.type or "CIRCLE" in self.type or "QUANTILE" in self.type or "S_Q" in self.type:
......
......@@ -10,9 +10,12 @@ class DataProviderGridBase(DataProviderBase):
super().__init__()
self.grid_labels = None
self.grid_size = None
def transform_to_2dim_grid_encoding(self, grid_size=10):
self.grid_size = grid_size
self.grid_labels = np.zeros((len(self.labels), 3))
n_rows = math.ceil(self.floorplan_height/grid_size)
......
......@@ -41,8 +41,8 @@ class UJIndoorLocProvider(DataProviderBase):
self.data_tensor = data.iloc[:, :520].to_numpy()
self.timestamps = data['TIMESTAMP'].to_numpy()
self.floorplan_width = 200.0 #np.max(self.labels[:, 0]) - np.min(self.labels[:, 0])
self.floorplan_height = 180.0#np.max(self.labels[:, 1]) - np.min(self.labels[:, 1])
self.floorplan_width = np.max(self.labels[:, 0]) - np.min(self.labels[:, 0]) # 200.0 #
self.floorplan_height = np.max(self.labels[:, 1]) - np.min(self.labels[:, 1]) # 180.0#np.max(self.labels[:, 1]) - np.min(self.labels[:, 1])
def set_missing_AP_val(self, before=100, after=-110.0):
mask = np.where(self.data_tensor == before)
......
......@@ -20,53 +20,6 @@ from numpy.random import seed
from tensorflow import set_random_seed
def point_uncertainty_estimation(conf_file, model_weights):
conf = ConfigReader(conf_file)
conf.setup_directories()
pipeline_params = conf.pipelines[0]
pre_params = conf.get_params('preprocessing', pipeline_params,
merge_level=1)
params = conf.get_params('model_params', pipeline_params,
merge_level=1)
# get data provider
dp = BboxPipeline.get_data_provider(conf.data_params,
pre_params)
# setup model
model = BboxModel(params['type'], None, dp, params,
conf.output_dir, pipeline_params['name'])
model.setup_model(setup_params=True)
model.load_weights(file=model_weights)
y_pred = model.classifier.predict(dp.data_tensor)
# setup new model that predicts boxes from positions as input
dp.data_tensor = np.zeros((len(dp.data_tensor), 2))
dp.data_tensor = y_pred[:, :2]
pipeline = BboxPipeline(dp,
None,
conf,
params,
pipeline_params['name'])
pipeline.k_fold_validation()
pipeline.store()
# new_model = BboxModel(params['type'], KFoldClassSummary([], [], []), dp, params,
# conf.output_dir, pipeline_params['name'])
#
# model.params['epochs'] = 1
# new_model.setup_model(setup_params=True)
# new_model.train_model()
# print('test')
def execute(conf_file):
area_classification = True
logging.basicConfig(level="INFO")
......@@ -102,18 +55,6 @@ def execute(conf_file):
# get data provider
base_data_provider = BboxPipeline.get_data_provider(conf.data_params, pre_params)
#mask = np.where(np.logical_and(base_data_provider.labels[:, 0] <= base_data_provider.floorplan_height, base_data_provider.labels[:, 1] <= base_data_provider.floorplan_height))[0]
#base_data_provider.labels = base_data_provider.labels[mask]
#base_data_provider.data_tensor = base_data_provider.data_tensor[mask]
#img = "evaluation/gia/gia_floor_4.jpg"
#img = resource_filename('data', 'lohan/CrowdsourcedDS1floor.png')
#fp = FloorplanPlot((83.32, 17.16), 2, floorplan_bg_img=img)
#fp = FloorplanPlot((200, 80), 4, floorplan_bg_img=img)
#fp.draw_points(base_data_provider.labels[:, 0], base_data_provider.labels[:, 1])
#fp.show_plot()
# for storing pipeline iteration names
p_names = []
......@@ -129,13 +70,6 @@ def execute(conf_file):
clusterer: ClusterBase = BboxPipeline.get_floor_plan_segmentation(
data_provider, fp_params)
#fp.draw_points(clusterer.base_clusters)
# if clusterer is not None:
# fp.draw_polygons(clusterer.areas)
# fp.draw_clusters(clusterer.base_clusters, noise=None)
# fp.show_plot()
# either use segmented floor plan or apply regression
if fp_params['type'] == 'segmentation':
......@@ -169,10 +103,10 @@ def execute(conf_file):
# compute grid encoding
if "GRID" in model_params['type']:
#data_provider.transform_to_grid_encoding()
data_provider.transform_to_2dim_grid_encoding(grid_size=40)
#data_provider.labels[:, 0] /= (data_provider.floorplan_width)
#data_provider.labels[:, 1] /= data_provider.floorplan_height
if "grid_size" in pre_params:
data_provider.transform_to_2dim_grid_encoding(grid_size=pre_params['grid_size'])
else:
data_provider.transform_to_grid_encoding()
pipeline = BboxPipeline(data_provider,
clusterer,
......@@ -199,32 +133,6 @@ def main():
execute(args.c)
def illustrate_results(file):
pipe: BboxPipeline = Storable.load(file)
img = "evaluation/gia/gia_floor_4.jpg"
img = resource_filename('data', 'lohan/CrowdsourcedDS1floor.png')
# setup floor plan plot
y_true = np.concatenate(pipe.summary.y_true_labels, axis=0)
y_pred = np.concatenate(pipe.summary.y_pred, axis=0)
calc_acc_c(y_true, y_pred)
print("center-dist: {}".format(center_diff(y_true, y_pred)))
#for idx in range(10):
max_el = 396
#fp = FloorPlanPlotRec((83.32, 17.16), 2, floorplan_bg_img=img)
# fp = FloorPlanPlotRec((200, 80), 4, floorplan_bg_img=img)
for idx in range(max_el):
idx += 0
fp = FloorPlanPlotRec((200, 80), 4, floorplan_bg_img=img)
fp.draw_points(y_true[idx, 0], y_true[idx, 1], color='g', alpha=0.5)
fp.draw_rectangles_new(y_pred[idx, :])
fp.show_plot()
def center_diff(y_true, y_pred):
return np.mean(np.linalg.norm(y_pred[:, :2] - y_true, axis=1))
......
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