π Geometric Computer Vision Library for Spatial AI
Python artificial-intelligencecomputer-visiondeep-learninghacktoberfestimage-processingmachine-learningneural-networkpythonpytorchroboticsspatial-ai
quaternion_to_angle_axis and rotation_matrix_to_quaternion only accepts batched input
edgarriba7dfed1f44c20
diff --git a/torchgeometry/conversions.py b/torchgeometry/conversions.pyindex 85e27773f..096e9781e 100644--- a/torchgeometry/conversions.py+++ b/torchgeometry/conversions.py@@ -303,10 +303,6 @@ def rotation_matrix_to_quaternion(rotation_matrix, eps=1e-6):raise TypeError("Input type is not a torch.Tensor. Got {}".format(type(rotation_matrix)))- input_shape = rotation_matrix.shape- if len(input_shape) == 2:- rotation_matrix = rotation_matrix.unsqueeze(0)-if len(rotation_matrix.shape) > 3:raise ValueError("Input size must be a three dimensional tensor. Got {}".format(@@ -360,9 +356,6 @@ def rotation_matrix_to_quaternion(rotation_matrix, eps=1e-6):q /= torch.sqrt(t0_rep * mask_c0 + t1_rep * mask_c1 # noqa+ t2_rep * mask_c2 + t3_rep * mask_c3) # noqaq *= 0.5-- if len(input_shape) == 2:- q = q.squeeze(0)return q@@ -389,11 +382,10 @@ def quaternion_to_angle_axis(quaternion, eps=1e-6):raise TypeError("Input type is not a torch.Tensor. Got {}".format(type(quaternion)))- input_shape = quaternion.shape- if len(input_shape) == 1:- quaternion = torch.unsqueeze(quaternion, dim=0)+ if len(quaternion.shape) != 2 and quaternion.shape[1] != 4:+ raise ValueError("Input must be a tensor of shape Nx4. Got {}".format(+ quaternion.shape))- assert quaternion.size(1) == 4, 'Input must be a vector of length 4'normalizer = 1 / torch.norm(quaternion, dim=1)q1 = quaternion[:, 1] * normalizerq2 = quaternion[:, 2] * normalizer@@ -426,9 +418,6 @@ def quaternion_to_angle_axis(quaternion, eps=1e-6):angle_axis[:, 1] = q2 * kangle_axis[:, 2] = q3 * k- if len(input_shape) == 1:- angle_axis = angle_axis.squeeze(0)-return angle_axis# TODO: add below funtionalities