Skip to content

Commit

Permalink
modified hnet loss
Browse files Browse the repository at this point in the history
  • Loading branch information
MaybeShewill-CV committed Oct 24, 2018
1 parent d8f16b2 commit 4c022f5
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions lanenet_model/lanenet_hnet_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def hnet_loss(gt_pts, transformation_coeffcient, name):
Y = tf.transpose(pts_projects[1, :])
X = tf.transpose(pts_projects[0, :])
Y_One = tf.add(tf.subtract(Y, Y), tf.constant(1.0, tf.float32))
Y_stack = tf.stack([tf.pow(Y, 2), Y, Y_One], axis=1)
Y_stack = tf.stack([tf.pow(Y, 3), tf.pow(Y, 2), Y, Y_One], axis=1)
w = tf.matmul(tf.matmul(tf.matrix_inverse(tf.matmul(tf.transpose(Y_stack), Y_stack)),
tf.transpose(Y_stack)),
tf.expand_dims(X, -1))
# 利用二阶多项式参数求解拟合位置并反算到原始投影空间计算损失
x_preds = tf.matmul(Y_stack, w)
preds = tf.transpose(tf.stack([tf.squeeze(x_preds, -1), Y, pts_projects[2, :]], axis=1))
preds = tf.transpose(tf.stack([tf.squeeze(x_preds, -1), Y, Y_One], axis=1))
x_transformation_back = tf.matmul(tf.matrix_inverse(H), preds)

loss = tf.reduce_mean(tf.pow(gt_pts[0, :] - x_transformation_back[0, :], 2))
Expand Down Expand Up @@ -71,25 +71,41 @@ def hnet_transformation(gt_pts, transformation_coeffcient, name):
Y = tf.transpose(pts_projects[1, :])
X = tf.transpose(pts_projects[0, :])
Y_One = tf.add(tf.subtract(Y, Y), tf.constant(1.0, tf.float32))
Y_stack = tf.stack([tf.pow(Y, 2), Y, Y_One], axis=1)
Y_stack = tf.stack([tf.pow(Y, 3), tf.pow(Y, 2), Y, Y_One], axis=1)
w = tf.matmul(tf.matmul(tf.matrix_inverse(tf.matmul(tf.transpose(Y_stack), Y_stack)),
tf.transpose(Y_stack)),
tf.expand_dims(X, -1))

# 利用二阶多项式参数求解拟合位置
x_preds = tf.matmul(Y_stack, w)
preds = tf.transpose(tf.stack([tf.squeeze(x_preds, -1), Y, pts_projects[2, :]], axis=1))
preds = tf.transpose(tf.stack([tf.squeeze(x_preds, -1), Y, Y_One], axis=1))
preds_fit = tf.stack([tf.squeeze(x_preds, -1), Y], axis=1)
x_transformation_back = tf.matmul(tf.matrix_inverse(H), preds)

return preds_fit
return x_transformation_back


if __name__ == '__main__':
gt_labels = tf.constant([[[1.0, 1.0, 1.0], [2.0, 2.0, 2.0], [3.0, 3.0, 3.0]],
[[1.0, 1.0, 1.0], [2.0, 2.0, 2.0], [3.0, 3.0, 3.0]]],
dtype=tf.float32, shape=[2, 3, 3])
transformation_coffecient = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], dtype=tf.float32, shape=[6])
gt_labels = tf.constant([[[1.0, 1.0, 1.0], [2.0, 2.0, 1.0], [3.0, 3.0, 1.0]],
[[1.0, 1.0, 1.0], [2.0, 2.0, 1.0], [3.0, 3.0, 1.0]]],
dtype=tf.float32, shape=[6, 3])
transformation_coffecient = tf.constant([[0.58348501, -0.79861236, 2.30343866,
-0.09976104, -1.22268307, 2.43086767]],
dtype=tf.float32, shape=[6])

# import numpy as np
# c_val = [0.58348501, -0.79861236, 2.30343866,
# -0.09976104, -1.22268307, 2.43086767]
# R = np.zeros([3, 3], np.float32)
# R[0, 0] = c_val[0]
# R[0, 1] = c_val[1]
# R[0, 2] = c_val[2]
# R[1, 1] = c_val[3]
# R[1, 2] = c_val[4]
# R[2, 1] = c_val[5]
# R[2, 2] = 1
#
# print(np.mat(R).I)

_loss = hnet_loss(gt_labels, transformation_coffecient, 'loss')

Expand Down

0 comments on commit 4c022f5

Please sign in to comment.