Commit 6a4143a1 authored by Marius Laska's avatar Marius Laska

loss function for rot box updated

parent fe270a6e
......@@ -26,9 +26,9 @@ def encode():
dp.encode_walls_to_2dim_overlapping_grid_encoding(walls_h, horizontal=True,
grid_size=40, width=200,
height=80)
dp.encode_walls_to_2dim_overlapping_grid_encoding(walls_v, horizontal=False,
grid_size=40, width=200,
height=80)
#dp.encode_walls_to_2dim_overlapping_grid_encoding(walls_v, horizontal=False,
# grid_size=40, width=200,
# height=80)
print("test")
if __name__ == '__main__':
......
No preview for this file type
......@@ -8,10 +8,62 @@ from analysis.visualize_learning_progress import convert_from_2dim_overlapping_r
from base.floor_plan_plot import FloorPlanPlotRec
import numpy as np
from shapely.geometry import Polygon
from base.custom_loss import compute_tf_loss
def compute_loss(y_true, y_pred, walls_h, walls_v):
test = compute_tf_loss(y_true, y_pred, walls_h, walls_v)
def main():
p: Pipeline = Storable.load("/home/laskama/PycharmProjects/bboxPrediction/evaluation/lohan/rot/output/BBOX_1l_20_aug_1")
p1 = 80
p2 = 86
w1 = 48
w2 = 50
p: Pipeline = Storable.load("/Users/mariuslaska/PycharmProjects/boxprediction/evaluation/lohan/rot/output/BBOX_1l_20_base_1")
p.data_provider.transform_to_2dim_overlapping_grid_encoding(
grid_size=40, labels=p.summary.y_true_labels[1])
y_true_enc = p.data_provider.grid_labels
y_pred_enc = p.summary.y_pred[1]
walls_h = np.load(
"/Users/mariuslaska/PycharmProjects/boxprediction/analysis/hor_walls.npy")
walls_v = np.load(
"/Users/mariuslaska/PycharmProjects/boxprediction/analysis/ver_walls.npy")
p.data_provider.encode_walls_to_2dim_overlapping_grid_encoding(
grid_size=40, horizontal=True,
walls=walls_h)
p.data_provider.encode_walls_to_2dim_overlapping_grid_encoding(
grid_size=40, horizontal=False,
walls=walls_v)
loss = compute_tf_loss(y_true_enc, y_pred_enc, p.data_provider.grid_walls_h, p.data_provider.grid_walls_v, modus="loss")
l_angle_diff_scale = compute_tf_loss(y_true_enc, y_pred_enc, p.data_provider.grid_walls_h, p.data_provider.grid_walls_v, modus="angle_diff_scale")
l_angle_diff = compute_tf_loss(y_true_enc, y_pred_enc, p.data_provider.grid_walls_h, p.data_provider.grid_walls_v, modus="angle_diff")
l_d_hor_pos = compute_tf_loss(y_true_enc, y_pred_enc,
p.data_provider.grid_walls_h,
p.data_provider.grid_walls_v,
modus="d_hor_pos")
l_d_hor_neg = compute_tf_loss(y_true_enc, y_pred_enc,
p.data_provider.grid_walls_h,
p.data_provider.grid_walls_v,
modus="d_hor_neg")
l_d_ver_pos = compute_tf_loss(y_true_enc, y_pred_enc,
p.data_provider.grid_walls_h,
p.data_provider.grid_walls_v,
modus="d_ver_pos")
l_d_ver_neg = compute_tf_loss(y_true_enc, y_pred_enc,
p.data_provider.grid_walls_h,
p.data_provider.grid_walls_v,
modus="d_ver_neg")
convert_from_2dim_overlapping_rotated_grid(p, grid_size=40,
quantile=False,
......@@ -19,22 +71,56 @@ def main():
average_samples=True)
y_pred_box = np.concatenate(p.summary.y_pred, axis=0)
y_pred_box = p.summary.y_pred[1]#[p1:p2, :]
y_true = p.summary.y_true_labels[1]
img = resource_filename('data', 'lohan/CrowdsourcedDS1floor.png')
fp_dims = (200, 80)
fp = FloorPlanPlotRec(fp_dims, 2, floorplan_bg_img=img)
#fp = FloorPlanPlotRec(fp_dims, 2, floorplan_bg_img=img, walls=walls_h[w1:w2, :])
for idx in range(200): # len(y_true)):
# check diff in angle
w_idx = np.argmax(l_angle_diff_scale[idx, :])
diff = y_pred_box[idx, 4] - p.data_provider.grid_walls_h[w_idx, 4]
walls_idx = np.where(l_angle_diff_scale[idx, :] != 0.0)[0]
for idx in range(100): # len(y_true)):
# check closest hor wall
h_w_idx_pos = np.argmin(np.abs(l_d_hor_pos[idx, :]))
h_w_idx_neg = np.argmin(np.abs(l_d_hor_neg[idx, :]))
poly = get_rotated_polygon(*y_pred_box[idx, :])
fp.draw_polygons([poly])
h_v_idx_pos = np.argmin(np.abs(l_d_ver_pos[idx, :]))
h_v_idx_neg = np.argmin(np.abs(l_d_ver_neg[idx, :]))
fp.draw_rectangles_new(anchors=y_pred_box[idx, :], color='black')
fp = FloorPlanPlotRec(fp_dims, 2, floorplan_bg_img=img,
walls=walls_h[walls_idx])#[w1:w2, :])
fp.show_plot()
#fp.draw_rectangles_new(anchors=y_pred_box[idx, :], color='black')
#for angle in np.arange(0, -1, -0.1):
# y_pred_box[idx, 4] = angle
poly_1 = get_rotated_polygon(*y_pred_box[idx, :])
w = y_pred_box[idx, 2]
y_pred_box[idx, 2] = y_pred_box[idx, 3]
y_pred_box[idx, 3] = w
poly_2 = get_rotated_polygon(*y_pred_box[idx, :])
fp.draw_polygons([poly_1])
# draw closest walls
fp.draw_lines(np.array([walls_h[h_w_idx_pos, 0], walls_h[h_w_idx_pos, 2]]), np.array([walls_h[h_w_idx_pos, 1], walls_h[h_w_idx_pos, 3]]))
fp.draw_lines(
np.array([walls_h[h_w_idx_neg, 0], walls_h[h_w_idx_neg, 2]]),
np.array([walls_h[h_w_idx_neg, 1], walls_h[h_w_idx_neg, 3]]))
fp.draw_points(y_true[idx, 0], y_true[idx, 1])
print("diff: {}, line: {}, box: {}".format(diff, p.data_provider.grid_walls_h[w_idx, 4], y_pred_box[idx, 4]))
fp.show_plot()
def get_rotated_polygon(cx, cy, w, h, omega):
omega = -omega#/2
center = np.array([cx, cy])
ll = np.array([cx - w/2.0, cy - h/2.0]) - center
......@@ -54,5 +140,113 @@ def get_rotated_polygon(cx, cy, w, h, omega):
return Polygon(np.array(exterior_r))
def rotate_around_point(p, omega, o=None):
p_man = np.copy(p)
if o is not None:
p_man -= o
px = p_man[0] * np.cos(omega * math.pi) - p_man[1] * np.sin(omega * math.pi)
py = p_man[1] * np.cos(omega * math.pi) + p_man[0] * np.sin(omega * math.pi)
p_man = np.array([px, py])
if o is not None:
p_man += o
return p_man
def loss_rotation_visualization():
import matplotlib.pyplot as plt
omega = -0.1666666666
fig = plt.figure()
grid_cell = np.array([[-1, -1], [1, -1], [1,1], [-1, 1], [-1,-1]])
hor_line = np.array([[0.2, 0.7], [0.5, 0.7]])
y_true = np.array([-0.5, 0.1])
center = np.array([-0.3, 0.4])
dims = np.array([0.3, 0.2])
ll = center - dims/2
ur = center + dims/2
lr = center + np.array([1, -1])*dims/2
ul = center + np.array([-1, 1])*dims/2
box = np.array([ll, lr, ur, ul, ll])
plt.scatter(y_true[0], y_true[1], color="blue")
plt.plot(box[:, 0], box[:, 1])
plt.plot(grid_cell[:, 0], grid_cell[:, 1])
plt.plot(hor_line[:, 0], hor_line[:, 1], color="orange")
plt.scatter(hor_line[0,0], hor_line[0, 1], color="blue")
plt.scatter(hor_line[1, 0], hor_line[1, 1], color="red")
y_t = rotate_around_point(y_true, omega)
grid_cell_rot = np.array([rotate_around_point(p, omega) for p in grid_cell])
plt.plot(grid_cell_rot[:, 0], grid_cell_rot[:, 1], color="red")
# rotate center of box but not dims
center_r = rotate_around_point(center, omega)
ll_r = center_r - dims / 2
ur_r = center_r + dims / 2
lr_r = center_r + np.array([1, -1]) * dims / 2
ul_r = center_r + np.array([-1, 1]) * dims / 2
box_r = np.array([ll_r, lr_r, ur_r, ul_r, ll_r])
plt.plot(box_r[:, 0], box_r[:, 1])
#box_rot = np.array([rotate_around_point(p, omega) for p in box])
#plt.plot(box_rot[:, 0], box_rot[:, 1], color="green")
line_center = np.mean(hor_line, axis=0)
line_rot = np.array([rotate_around_point(p, -omega, o=hor_line[0, :]) for p in hor_line])
plt.plot(line_rot[:, 0], line_rot[:, 1], color="orange")
plt.scatter(line_rot[0, 0], line_rot[0, 1], color="blue")
plt.scatter(line_rot[1, 0], line_rot[1, 1], color="red")
# get omega of rotated line
omega_1 = np.arctan2(
line_rot[1, 1] - line_rot[0, 1], line_rot[1, 0] - line_rot[0, 0]) /math.pi
print(omega_1)
plt.scatter(y_t[0], y_t[1], color="green")
plt.axis('equal')
plt.show()
def test_vis():
p1 = np.array([1.0, 1.0])
p2 = np.array([3.0, 1.0])
line = np.array([p1,p2])
omega = 0.25
center = np.mean(line, axis=0)
rot = np.array([rotate_around_point(p, omega, o=center) for p in line])
import matplotlib.pyplot as plt
plt.figure()
plt.scatter(line[:, 0], line[:, 1])
plt.scatter(rot[:, 0], rot[:, 1])
plt.plot(line[:, 0], line[:, 1])
plt.plot(rot[:, 0], rot[:, 1])
plt.axis('equal')
plt.show()
if __name__ == '__main__':
#test_vis()
#loss_rotation_visualization()
main()
\ No newline at end of file
......@@ -77,7 +77,10 @@ class BboxModel(DnnModel):
elif self.type == "GRID_ROT-BBOX":
if 'loss' in params:
loss_func = define_rotated_box_loss(params['loss'])
loss_func = define_rotated_box_loss(
params['loss'],
tf_walls_h=self.data_provider.grid_walls_h,
tf_walls_v=self.data_provider.grid_walls_v)
params.update({'last_activation': tanh,
'losses': loss_func})
......
......@@ -969,9 +969,15 @@ def define_yolo_loss_tanh_no_size(params):
return yolo_loss
def define_rotated_box_loss(params, walls_h, walls_v):
def define_rotated_box_loss(params, tf_walls_h, tf_walls_v, modus="loss"):
import math as m
tf_PI = tf.constant(m.pi)
walls_h = tf.constant(tf_walls_h, dtype=tf.float32)
walls_v = tf.constant(tf_walls_v, dtype=tf.float32)
MAX_DIST = tf.constant(100, dtype=tf.float32)
# mask to select columns of wall tensor that includes everything but angle
non_omega_idx = tf.constant([0, 1, 2, 3, 5], dtype=tf.int32)
def yolo_loss(y_true, y_pred):
......@@ -1029,8 +1035,35 @@ def define_rotated_box_loss(params, walls_h, walls_v):
# Wall loss (before rotation)
#
# calculate mask that stores whether wall is in grid cell of ground truth
# helping tensor that contains all horizontal walls without the angle
# parameter, such that it can be concatenated with vertical walls
# that do not include encoded angle
walls_h_no_omega = tf.concat([walls_h[:, :4], tf.reshape(walls_h[:, 5], [-1, 1])], axis=1)
walls = tf.concat([walls_h_no_omega, walls_v], axis=0)
wall_cell_mask_bool = tf.equal(tf.reshape(y_true[:, 2], [-1, 1]),
tf.reshape(walls[:, 4], [1, -1]))
wall_cell_mask = tf.cast(wall_cell_mask_bool, tf.float32)
wall_cell_mask_float = tf.add(
tf.cast(wall_cell_mask_bool, tf.float32),
tf.cast(~wall_cell_mask_bool, tf.float32) * MAX_DIST)
wall_h_cell_mask = tf.cast(tf.equal(tf.reshape(y_true[:, 2], [-1, 1]),
tf.reshape(walls_h[:, 4], [1, -1])), tf.float32)
wall_v_cell_mask = tf.cast(tf.equal(tf.reshape(y_true[:, 2], [-1, 1]),
tf.reshape(walls_v[:, 4], [1, -1])), tf.float32)
# get subset of walls that is within
# 1) compute distance from centers to walls (dist_walls)
walls = tf.concat([walls_h[:, :4], walls_v], axis=0)
test_res = tf.matmul(
tf.reshape(y_pred_s[:, 0], [-1, 1]),
tf.reshape((walls[:, 3] - walls[:, 1]), [1, -1]))
nom = tf.matmul(
tf.reshape(y_pred_s[:, 0], [-1, 1]),
......@@ -1041,19 +1074,78 @@ def define_rotated_box_loss(params, walls_h, walls_v):
+ walls[:, 2] * walls[:, 1] \
- walls[:, 3] * walls[:, 0]
# mask to only include walls within grid cell
nom = nom * wall_cell_mask #+ tf.cast(~wall_cell_mask_bool, tf.float32) * MAX_DIST
nom = tf.where(~wall_cell_mask_bool, tf.ones_like(nom)*MAX_DIST, nom)
#nom = tf.assign(nom, tf.where(wall_cell_mask_bool, tf.zeros_like(nom), nom))
denom = tf.square(walls[:, 3] - walls[:, 1]) + tf.square(walls[:, 2] - walls[:, 0])
# mask to only include walls within grid cell
denom = tf.reshape(tf.tile(denom, [tf.shape(y_true)[0]]), [-1, tf.shape(wall_cell_mask_float)[1]])
denom = tf.where(~wall_cell_mask_bool, tf.ones_like(denom) * MAX_DIST, denom)
dist_walls = tf.abs(nom) / tf.sqrt(denom)
# 2) compute dist between horizontal box boundary and horizontal walls
# compute center of horizontal walls
walls_h_center_x = tf.reduce_mean(tf.concat(
[tf.reshape(walls_h[:, 0], [-1, 1]),
tf.reshape(walls_h[:, 2], [-1, 1])], axis=1), axis=1)
walls_h_center_y = tf.reduce_mean(tf.concat(
[tf.reshape(walls_h[:, 1], [-1, 1]),
tf.reshape(walls_h[:, 3], [-1, 1])], axis=1), axis=1)
walls_h_center = tf.concat([tf.reshape(walls_h_center_x, [-1, 1]),
tf.reshape(walls_h_center_y, [-1, 1])],
axis=1)
d_hor = tf.transpose(tf.transpose(
dist_walls[:, :tf.shape(walls_h)[0]]) - y_pred_s[:, 3]/2)
d_hor = tf.where(~wall_cell_mask_bool[:, :tf.shape(walls_h)[0]], tf.ones_like(d_hor)*MAX_DIST, d_hor)
pos_mask = tf.reshape(y_pred_s[:, 1], [-1, 1]) > tf.reshape(walls_h_center[:, 1], [1, -1])
d_hor_pos_only = tf.where(pos_mask, tf.ones_like(d_hor)*MAX_DIST, d_hor)
d_hor_neg_only = tf.where(~pos_mask, tf.ones_like(d_hor) * MAX_DIST,
d_hor)
d_ver = tf.transpose(tf.transpose(
dist_walls[:, tf.shape(walls_h)[0]:]) - y_pred_s[:, 2]/2)
d_ver = tf.where(~wall_cell_mask_bool[:, tf.shape(walls_h)[0]:], tf.ones_like(d_ver)*MAX_DIST, d_ver)
# compute center of vertical walls
walls_v_center_x = tf.reduce_mean(tf.concat(
[tf.reshape(walls_v[:, 0], [-1, 1]),
tf.reshape(walls_v[:, 2], [-1, 1])], axis=1), axis=1)
walls_v_center_y = tf.reduce_mean(tf.concat(
[tf.reshape(walls_v[:, 1], [-1, 1]),
tf.reshape(walls_v[:, 3], [-1, 1])], axis=1), axis=1)
wall_loss_hor = tf.reduce_min(tf.abs(d_hor), axis=1)
wall_loss_ver = tf.reduce_min(tf.abs(d_ver), axis=1)
walls_v_center = tf.concat([tf.reshape(walls_v_center_x, [-1, 1]), tf.reshape(walls_v_center_y, [-1, 1])], axis=1)
loss += wall_loss_hor + wall_loss_ver
pos_mask = tf.reshape(y_pred_s[:, 0], [-1, 1]) > tf.reshape(
walls_v_center[:, 0], [1, -1])
d_ver_pos_only = tf.where(pos_mask, tf.ones_like(d_ver) * MAX_DIST,
d_ver)
d_ver_neg_only = tf.where(~pos_mask, tf.ones_like(d_ver) * MAX_DIST,
d_ver)
wall_loss_hor = tf.reduce_min(tf.abs(d_hor_pos_only), axis=1) + tf.reduce_min(tf.abs(d_hor_neg_only), axis=1)
wall_loss_ver = tf.reduce_min(tf.abs(d_ver_pos_only), axis=1) + tf.reduce_min(tf.abs(d_ver_neg_only), axis=1)
#wall_loss_hor = tf.reduce_min(tf.abs(d_hor), axis=1)
#wall_loss_ver = tf.reduce_min(tf.abs(d_ver), axis=1)
wall_loss_sum = tf.reduce_sum(tf.multiply(grid_cell_pred, grid_cell_true), axis=1) * (wall_loss_hor + wall_loss_ver)
loss += tf.constant(0.1) * wall_loss_sum
#
# Angle diff to horizontal walls (inversely weighted by distance)
......@@ -1065,11 +1157,13 @@ def define_rotated_box_loss(params, walls_h, walls_v):
tf.reduce_min(
dist_walls[:, :tf.shape(walls_h)[0]], axis=1))
angle_diff = angle_diff_scale * (
tf.reshape(y_pred_s[:, 4], [-1, 1]) -
tf.reshape(walls_h[:, 4], [1, -1]))
angle_diff_scale = tf.where(~wall_cell_mask_bool[:, :tf.shape(walls_h)[0]], tf.zeros_like(angle_diff_scale), angle_diff_scale)
loss += tf.reduce_sum(angle_diff, axis=1)
angle_diff = tf.square(tf.reshape(y_pred_s[:, 4], [-1, 1]) - tf.reshape(walls_h[:, 4], [1, -1]))
angle_diff_loss = tf.square(angle_diff_scale) * angle_diff
loss += tf.reduce_sum(tf.multiply(grid_cell_pred, grid_cell_true), axis=1) * tf.reduce_sum(angle_diff_loss, axis=1)
#
# following operations are computed with rotated local coordinate system
......@@ -1090,7 +1184,7 @@ def define_rotated_box_loss(params, walls_h, walls_v):
# box loss
box_loss = tf.zeros_like(y_true[:, 0])
box_loss_scale = tf.reduce_sum(tf.multiply(grid_cell_pred, grid_cell_true))
box_loss_scale = tf.reduce_sum(tf.multiply(grid_cell_pred, grid_cell_true), axis=1)
# center loss
c_loss = tf.reduce_sum(tf.square(tf.subtract(y_true[:, :2], y_pred_s[:, :2])),
......@@ -1127,7 +1221,26 @@ def define_rotated_box_loss(params, walls_h, walls_v):
loss += box_loss * box_loss_scale
return loss
if modus == "loss":
return loss
if modus == "angle_diff_scale":
return angle_diff_scale#angle_diff_scale
if modus == "angle_diff":
return angle_diff
if modus == "d_hor_pos":
return d_hor_pos_only
if modus == "d_hor_neg":
return d_hor_neg_only
if modus == "d_ver_pos":
return d_ver_pos_only
if modus == "d_ver_neg":
return d_ver_neg_only
if modus == "d_ver":
return d_ver
if modus == "wall_loss_hor":
return wall_loss_hor
if modus == "wall_loss_ver":
return wall_loss_ver
return yolo_loss
......@@ -1361,6 +1474,29 @@ def test_hier_loss():
#writer.close()
def compute_tf_loss(y_true, y_pred, walls_h, walls_v, modus="loss"):
init = tf.global_variables_initializer()
y_true = tf.constant(y_true, dtype=tf.float32)
y_pred = tf.constant(y_pred, dtype=tf.float32)
loss_func = define_rotated_box_loss(
params=dict(grid={"scale": 20.0},
outside={"scale": 0.1,
"delta": 20.0}),
tf_walls_h=walls_h, tf_walls_v=walls_v, modus=modus)
with tf.Session() as sess:
# Run the initializer on `w`.
sess.run(init)
result = sess.run(loss_func(y_true, y_pred))
print(result)
writer = tf.summary.FileWriter("output", sess.graph)
writer.close()
return result
def test_yolo_loss():
init = tf.global_variables_initializer()
......@@ -1368,8 +1504,8 @@ def test_yolo_loss():
y_pred = np.array([[0.7, 0.3, 0.5, 0.2, 0, 0.6, 0.4, 0.2, 0.9, 0.1,0, -0.4], [0.3, 0.2, 0.4, 0.1, 0, -0.2, 0.2, 0.2, 0.6, 0.1,0, -0.8]])
walls_h = np.array([[-0.7, 0.2, 0.5, 0.2, 0], [0.6, 0.4, 0.2, 0.9, 0.1], [-0.7, 0.2, 0.5, 0.1, -0.5]])
walls_v = np.array([[-0.7, 0.2, 0.5, 0.1], [-0.6, 0.4, 0.2, 0.9]])
walls_h = np.array([[-0.7, 0.2, 0.5, 0.2, 0, 1], [0.6, 0.4, 0.2, 0.9, 0.1, 0], [-0.7, 0.2, 0.5, 0.1, -0.5, 0]])
walls_v = np.array([[-0.7, 0.2, 0.5, 0.1, 1], [-0.6, 0.4, 0.2, 0.9, 1]])
#c_sub = y_pred[:, [0::, 1]*5]
......@@ -1378,14 +1514,12 @@ def test_yolo_loss():
y_true = tf.constant(y_true, dtype=tf.float32)
y_pred = tf.constant(y_pred, dtype=tf.float32)
walls_h_tf = tf.constant(walls_h, dtype=tf.float32)
walls_v_tf = tf.constant(walls_v, dtype=tf.float32)
loss_func = define_rotated_box_loss(
params=dict(grid={"scale": 4.0},
size={"scale": 0.0055},
outside={"scale": 0.1}),
walls_h=walls_h_tf, walls_v=walls_v_tf)
tf_walls_h=walls_h, tf_walls_v=walls_v)
with tf.Session() as sess:
# Run the initializer on `w`.
......@@ -1666,6 +1800,13 @@ def test():
if __name__ == "__main__":
y_pred_s = np.array([[0,1], [1,2], [3,0]])
walls = np.array([[1,0,1,2],[2,1,1,3],[1,0,1,4],[2,5,1,4]])
test_res = np.matmul(
np.reshape(y_pred_s[:, 0], [-1, 1]),
np.reshape((walls[:, 3] - walls[:, 1]), [1, -1]))
test_yolo_loss()
# test = np.array([[1,2,5,4,5,6], [1,2,5,4,5,6], [7,2,5,4,5,6], [1,2,5,4,7,6]])
......
......@@ -109,7 +109,7 @@ class DataProviderGridBase(DataProviderBase):
img = resource_filename('data', 'lohan/CrowdsourcedDS1floor.png')
linewidth = 2
fp = FloorPlanPlotRec((200, 80), 2, floorplan_bg_img=img)
#fp = FloorPlanPlotRec((200, 80), 2, floorplan_bg_img=img)
if labels is None:
labels = self.labels
......@@ -142,7 +142,7 @@ class DataProviderGridBase(DataProviderBase):
y = r_idx * grid_size
origins.append(np.array([x, y]))
fp.axis.text(x+1, y-2, str(idx))
#fp.axis.text(x+1, y-2, str(idx))
# Determine closest origin for labels (the corresponding cell is
# responsible for encoding
......@@ -151,20 +151,20 @@ class DataProviderGridBase(DataProviderBase):
origins = np.array(origins)
fp.draw_rectangles_new(o_plt, color="black")
fp.draw_rectangles_new(o_plt_pad, color="grey")
#fp.draw_rectangles_new(o_plt, color="black")
#fp.draw_rectangles_new(o_plt_pad, color="grey")
#fp.draw_rectangles_new(o_plt[7], color="green")
#fp.draw_rectangles_new(o_plt_pad[[1,2,6]], color="blue")
fp.draw_points(origins[:, 0], origins[:, 1], color="black")
#fp.draw_points(origins[:, 0], origins[:, 1], color="black")
#fp.draw_points([62], [21], color="green")
o_vals = np.array([7,1,2,6])
test = (np.array([[62, 21]]) - origins[o_vals, :]) / (grid_size / 2.0 + grid_size * padding_ratio)
print(np.concatenate((test, o_vals.reshape(-1, 1)), axis=1))
fp.show_plot()
#fp.show_plot()
dist_to_center = np.full((len(labels), len(origins)), np.inf)
dist_to_center_cmp = np.full((len(labels), len(origins), 2), np.inf)
......@@ -284,12 +284,26 @@ class DataProviderGridBase(DataProviderBase):
resp_grid_center_line_idx = resp_grid_center_line_idx[no_split_required]
resp_grid_center_origins = resp_grid_center_origins[no_split_required, :]
if horizontal:
grid_encoding = np.zeros((len(walls[:, :2]), 6))
grid_encoding[:, 5] = resp_grid_center_line_idx
# calculate angle
omega = -np.arctan(
(walls[:, 3] - walls[:, 1]) / (walls[:, 2] - walls[:, 0])) / math.pi
grid_encoding[:, 4] = omega
else:
grid_encoding = np.zeros((len(walls[:, :2]), 5))
grid_encoding[:, 4] = resp_grid_center_line_idx
# determine final encoding
grid_encoding = np.zeros((len(walls[:, :2]), 5))