Convert 6D rotation representation to 3x3 rotation matrix. Based on Zhou et al., "On the Continuity of Rotation Representations in Neural Networks", CVPR 2019 Input: (B,6) Batch of 6-D rotation representations Output: (B,3,3) Batch of corresponding rotation matrices
(x)
| 51 | |
| 52 | |
| 53 | def rot6d_to_rotmat(x): |
| 54 | """Convert 6D rotation representation to 3x3 rotation matrix. |
| 55 | |
| 56 | Based on Zhou et al., "On the Continuity of Rotation |
| 57 | Representations in Neural Networks", CVPR 2019 |
| 58 | Input: |
| 59 | (B,6) Batch of 6-D rotation representations |
| 60 | Output: |
| 61 | (B,3,3) Batch of corresponding rotation matrices |
| 62 | """ |
| 63 | if isinstance(x, torch.Tensor): |
| 64 | x = x.reshape(-1, 3, 2) |
| 65 | elif isinstance(x, np.ndarray): |
| 66 | x = x.view(-1, 3, 2) |
| 67 | a1 = x[:, :, 0] |
| 68 | a2 = x[:, :, 1] |
| 69 | b1 = F.normalize(a1) |
| 70 | b2 = F.normalize(a2 - torch.einsum('bi,bi->b', b1, a2).unsqueeze(-1) * b1) |
| 71 | b3 = torch.cross(b1, b2) |
| 72 | return torch.stack((b1, b2, b3), dim=-1) |
| 73 | |
| 74 | def rot6d_to_axis_angle(x): |
| 75 | batch_size = x.shape[0] |
no outgoing calls
no test coverage detected