test_fc_module.py 929 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. from unittest import TestCase
  3. import torch
  4. from mmdet.models import FcModule
  5. class TestFcModule(TestCase):
  6. def test_forward(self):
  7. inputs = torch.rand(32, 128)
  8. # test
  9. fc = FcModule(
  10. in_channels=128,
  11. out_channels=32,
  12. )
  13. fc.init_weights()
  14. outputs = fc(inputs)
  15. assert outputs.shape == (32, 32)
  16. # test with norm
  17. fc = FcModule(
  18. in_channels=128,
  19. out_channels=32,
  20. norm_cfg=dict(type='BN1d'),
  21. )
  22. outputs = fc(inputs)
  23. assert outputs.shape == (32, 32)
  24. # test with norm and act
  25. fc = FcModule(
  26. in_channels=128,
  27. out_channels=32,
  28. norm_cfg=dict(type='BN1d'),
  29. act_cfg=dict(type='ReLU'),
  30. )
  31. outputs = fc(inputs)
  32. assert outputs.shape == (32, 32)