Standardize matrix_to_quaternion output

Summary:
An OSS user has pointed out in https://github.com/facebookresearch/pytorch3d/issues/1703 that the output of matrix_to_quaternion (in that file) can be non standardized.

This diff solves the issue by adding a line of standardize at the end of the function

Reviewed By: bottler

Differential Revision: D52368721

fbshipit-source-id: c8d0426307fcdb7fd165e032572382d5ae360cde
This commit is contained in:
Abdelrahman Selim 2023-12-21 13:43:29 -08:00 committed by Facebook GitHub Bot
parent e46ab49a34
commit 3087ab7f62

View File

@ -155,10 +155,10 @@ def matrix_to_quaternion(matrix: torch.Tensor) -> torch.Tensor:
# if not for numerical problems, quat_candidates[i] should be same (up to a sign), # if not for numerical problems, quat_candidates[i] should be same (up to a sign),
# forall i; we pick the best-conditioned one (with the largest denominator) # forall i; we pick the best-conditioned one (with the largest denominator)
out = quat_candidates[
return quat_candidates[
F.one_hot(q_abs.argmax(dim=-1), num_classes=4) > 0.5, : F.one_hot(q_abs.argmax(dim=-1), num_classes=4) > 0.5, :
].reshape(batch_dim + (4,)) ].reshape(batch_dim + (4,))
return standardize_quaternion(out)
def _axis_angle_rotation(axis: str, angle: torch.Tensor) -> torch.Tensor: def _axis_angle_rotation(axis: str, angle: torch.Tensor) -> torch.Tensor: