From 3087ab7f62b5d581a133e54849d462f37fdf4c2d Mon Sep 17 00:00:00 2001 From: Abdelrahman Selim Date: Thu, 21 Dec 2023 13:43:29 -0800 Subject: [PATCH] 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 --- pytorch3d/transforms/rotation_conversions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pytorch3d/transforms/rotation_conversions.py b/pytorch3d/transforms/rotation_conversions.py index b5f73bf5..459441ca 100644 --- a/pytorch3d/transforms/rotation_conversions.py +++ b/pytorch3d/transforms/rotation_conversions.py @@ -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), # forall i; we pick the best-conditioned one (with the largest denominator) - - return quat_candidates[ + out = quat_candidates[ F.one_hot(q_abs.argmax(dim=-1), num_classes=4) > 0.5, : ].reshape(batch_dim + (4,)) + return standardize_quaternion(out) def _axis_angle_rotation(axis: str, angle: torch.Tensor) -> torch.Tensor: