test_efficientnet.py 859 B

12345678910111213141516171819202122232425
  1. import pytest
  2. import torch
  3. from mmdet.models.backbones import EfficientNet
  4. def test_efficientnet_backbone():
  5. """Test EfficientNet backbone."""
  6. with pytest.raises(AssertionError):
  7. # EfficientNet arch should be a key in EfficientNet.arch_settings
  8. EfficientNet(arch='c3')
  9. model = EfficientNet(arch='b0', out_indices=(0, 1, 2, 3, 4, 5, 6))
  10. model.train()
  11. imgs = torch.randn(2, 3, 32, 32)
  12. feat = model(imgs)
  13. assert len(feat) == 7
  14. assert feat[0].shape == torch.Size([2, 32, 16, 16])
  15. assert feat[1].shape == torch.Size([2, 16, 16, 16])
  16. assert feat[2].shape == torch.Size([2, 24, 8, 8])
  17. assert feat[3].shape == torch.Size([2, 40, 4, 4])
  18. assert feat[4].shape == torch.Size([2, 112, 2, 2])
  19. assert feat[5].shape == torch.Size([2, 320, 1, 1])
  20. assert feat[6].shape == torch.Size([2, 1280, 1, 1])