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

so3_log_map unexpected behaviour #262

Closed
eduardohenriquearnold opened this issue Jul 10, 2020 · 3 comments
Closed

so3_log_map unexpected behaviour #262

eduardohenriquearnold opened this issue Jul 10, 2020 · 3 comments
Assignees
Labels
question Further information is requested

Comments

@eduardohenriquearnold
Copy link
Contributor

Unexpected output of so3_log_map. so3_log_map and so3_exponential_map are inverse functions. However composing them for some rotation matrices do not result in the original rotation matrix R. Please note the code below.

Instructions To Reproduce the Issue:

import torch
from pytorch3d.transforms import so3_exponential_map, so3_log_map
from pytorch3d.renderer import look_at_view_transform

R,T = look_at_view_transform(1, elev=50, azim=0)
print(R)

log_R = so3_log_map(R, 1e-8)
R_hat = so3_exponential_map(log_R)
print(R_hat)

The output is

tensor([[[-1.0000,  0.0000,  0.0000],
         [ 0.0000,  0.6428, -0.7660],
         [-0.0000, -0.7660, -0.6428]]])
tensor([[[1., 0., 0.],
         [0., 1., 0.],
         [0., 0., 1.]]])

The matrices do not match, as one would expect. I cannot tell why, but I have noticed that this happens for any elevation angle <90 when azim=0.

@gkioxari gkioxari added the question Further information is requested label Jul 12, 2020
@davnov134
Copy link
Contributor

Hi,

unfortunately, for rotation angles close to PI or 0, the so3_log_map is (by definition) numerically unstable due to divisions by zero.

For more details on why this happens, please refer to https://en.wikipedia.org/wiki/Axis%E2%80%93angle_representation#:~:text=In%20mathematics%2C%20the%20axis%E2%80%93angle,the%20rotation%20about%20the%20axis , section "Exponential map from so(3) to SO(3)"

For better numerical stability you might want to switch to quaternions that do not suffer from these issues.

@eduardohenriquearnold
Copy link
Contributor Author

Hi. Sorry, I should have realised this earlier. Thanks for the great explanation though.

@tomer-grin
Copy link

tomer-grin commented Jan 16, 2022

@davnov134
Hey,
I also encountered this issue (within a bigger pipeline).
It caused problems on a few samples and diving into them revealed this issue.
does it make sense to add a warning to so3_log_map function when the input matrix might be close to 0?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants