Created
November 14, 2024 01:16
-
-
Save sherwoac/1f3c00d1df9d233f92441553264826f6 to your computer and use it in GitHub Desktop.
find the characteristic deltas between two sets of quaternions, then sample based on that and check the results are similar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kornia as kn | |
import kornia.geometry | |
import kornia.geometry.quaternion | |
def try_random(): | |
""" | |
- for two sets of poses A and B | |
- find the rotations between them, A->B = d1 | |
- find the standard deviation of the components of d rotation | |
- sample some random quaternions, C | |
- scale the the components according the standard deviation and re-normalize | |
- rotate A by C to get new sampled B2 | |
- find differences between A->B2 = d2 | |
- compare the resulting deltas d1, d2 | |
""" | |
with torch.no_grad(): | |
# two sets of random rotations as per: https://lavalle.pl/planning/node198.html | |
# gt and inferred pose, say: | |
A_q = kornia.geometry.quaternion.Quaternion.random(10, device='cuda') | |
B_q = kornia.geometry.quaternion.Quaternion.random(10, device='cuda') | |
# what's the (rotational) difference between the two sets of quats? Now find the std for each component | |
d1_q = B_q * A_q.inv() | |
delta_std = d1_q.data.std(dim=-2) | |
# let's sample some (small?) random rotations, scale the std according to above | |
C_q = kornia.geometry.quaternion.Quaternion.random(10, device='cuda') | |
C_q = kornia.geometry.quaternion.Quaternion(C_q.data * delta_std) | |
C_q.normalize() | |
# now perturb the gt data, multiply quats = rotate | |
B2_q = C_q * A_q | |
# calc the difference with gt | |
d2_q = B2_q * A_q.inv() | |
# why are they different? | |
print(d1_q.polar_angle.mean(), d2_q.polar_angle.mean()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment