Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

infinite values for RotationMatrixToAngleAxis (Op and Gradient) #18

Open
sikelerd opened this issue Jun 26, 2019 · 0 comments
Open

infinite values for RotationMatrixToAngleAxis (Op and Gradient) #18

sikelerd opened this issue Jun 26, 2019 · 0 comments

Comments

@sikelerd
Copy link

There is already a special handling for rotations about 0° but for a rotation about 180° there is no.
If trace of the rotation matrix is -1, theta becomes pi and any division by sin(theta) gives infinite values.

T tmp = R.trace()-1;
T theta = std::acos(std::min(T(1),std::max(T(-1),T(0.5)*tmp)));

Example

rot = np.array([[
        [-0.994789, 0.0789573, -0.0644982],
        [0.0790982, 0.198569, -0.97689],
        [-0.0643253, -0.976901, -0.20378]
]])

with tf.Session() as sess:
    r = tf.Variable(rot, dtype=tf.float32)
    sess.run(tf.global_variables_initializer())
    aa = sops.rotation_matrix_to_angle_axis(r)
    loss = tf.reduce_mean(sops.angle_axis_to_rotation_matrix(aa) - r)
    var_grad = tf.gradients(loss, [r])

    print(aa.eval())
    # [[  197.05762  3106.6025  -2531.7622 ]] norm: 4012.4346

    print(var_grad[0].eval())
    # [[[ inf  inf  inf]
    #  [-inf  inf -inf]
    #  [-inf  inf  inf]]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant