-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
168 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,84 @@ | ||
from torchdrive.tasks.diff_traj import XYEmbedding | ||
|
||
import unittest | ||
|
||
import torch | ||
from torchdrive.tasks.diff_traj import XEmbedding, XYEmbedding, XYLinearEmbedding | ||
|
||
|
||
class TestDiffTraj(unittest.TestCase): | ||
def test_diff_traj(self): | ||
dim = 20 | ||
def test_xy_embedding(self): | ||
torch.manual_seed(0) | ||
|
||
dim = 32 | ||
|
||
traj = XYEmbedding( | ||
shape=(16, 24), | ||
dim=dim, | ||
scale=1.0, | ||
) | ||
|
||
input = torch.tensor([ | ||
(0.0, 0.0), | ||
(1.0, 0.0), | ||
(0.0, 1.0), | ||
(-1.0, 0.0), | ||
(0.0, -1.0), | ||
]).unsqueeze(0) | ||
input = torch.tensor( | ||
[ | ||
(0.0, 0.0), | ||
(1.0, 0.0), | ||
(0.0, 1.0), | ||
(-1.0, 0.0), | ||
(0.0, -1.0), | ||
] | ||
).unsqueeze(0) | ||
|
||
output = traj(input) | ||
self.assertEqual(output.shape, (1, 5, dim)) | ||
|
||
positions = traj.decode(output) | ||
self.assertEqual(positions.shape, (1, 5, 2)) | ||
torch.testing.assert_close(positions, input) | ||
|
||
def test_xy_linear_embedding(self): | ||
torch.manual_seed(0) | ||
|
||
dim = 32 | ||
|
||
traj = XYLinearEmbedding( | ||
shape=(16, 24), | ||
dim=dim, | ||
scale=1.0, | ||
) | ||
|
||
input = torch.tensor( | ||
[ | ||
(0.0, 0.0), | ||
(1.0, 0.0), | ||
(0.0, 1.0), | ||
(-1.0, 0.0), | ||
(0.0, -1.0), | ||
] | ||
).unsqueeze(0) | ||
|
||
output = traj(input) | ||
self.assertEqual(output.shape, (1, 5, dim)) | ||
|
||
positions = traj.decode(output) | ||
self.assertEqual(positions.shape, (1, 5, 2)) | ||
torch.testing.assert_close(positions, input) | ||
|
||
def test_x_embedding(self): | ||
torch.manual_seed(0) | ||
|
||
dim = 20 | ||
|
||
traj = XEmbedding(shape=16, dim=dim, scale=1.0) | ||
|
||
input = torch.tensor( | ||
[ | ||
0.0, | ||
-1.0, | ||
1.0, | ||
] | ||
).unsqueeze(0) | ||
|
||
output = traj(input) | ||
self.assertEqual(output.shape, (1, 3, dim)) | ||
|
||
positions = traj.decode(output) | ||
self.assertEqual(positions.shape, (1, 3)) | ||
torch.testing.assert_close(positions, input) |