Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

test_architecture_ops.py 1.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  1. import unittest
  2. import pytest
  3. import torch
  4. from torchvision.models.maxvit import SwapAxes, WindowDepartition, WindowPartition
  5. class MaxvitTester(unittest.TestCase):
  6. def test_maxvit_window_partition(self):
  7. input_shape = (1, 3, 224, 224)
  8. partition_size = 7
  9. n_partitions = input_shape[3] // partition_size
  10. x = torch.randn(input_shape)
  11. partition = WindowPartition()
  12. departition = WindowDepartition()
  13. x_hat = partition(x, partition_size)
  14. x_hat = departition(x_hat, partition_size, n_partitions, n_partitions)
  15. torch.testing.assert_close(x, x_hat)
  16. def test_maxvit_grid_partition(self):
  17. input_shape = (1, 3, 224, 224)
  18. partition_size = 7
  19. n_partitions = input_shape[3] // partition_size
  20. x = torch.randn(input_shape)
  21. pre_swap = SwapAxes(-2, -3)
  22. post_swap = SwapAxes(-2, -3)
  23. partition = WindowPartition()
  24. departition = WindowDepartition()
  25. x_hat = partition(x, n_partitions)
  26. x_hat = pre_swap(x_hat)
  27. x_hat = post_swap(x_hat)
  28. x_hat = departition(x_hat, n_partitions, partition_size, partition_size)
  29. torch.testing.assert_close(x, x_hat)
  30. if __name__ == "__main__":
  31. pytest.main([__file__])
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...