test_detectors_resnet.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import pytest
  3. from mmdet.models.backbones import DetectoRS_ResNet
  4. def test_detectorrs_resnet_backbone():
  5. detectorrs_cfg = dict(
  6. depth=50,
  7. num_stages=4,
  8. out_indices=(0, 1, 2, 3),
  9. frozen_stages=1,
  10. norm_cfg=dict(type='BN', requires_grad=True),
  11. norm_eval=True,
  12. style='pytorch',
  13. conv_cfg=dict(type='ConvAWS'),
  14. sac=dict(type='SAC', use_deform=True),
  15. stage_with_sac=(False, True, True, True),
  16. output_img=True)
  17. """Test init_weights config"""
  18. with pytest.raises(AssertionError):
  19. # pretrained and init_cfg cannot be specified at the same time
  20. DetectoRS_ResNet(
  21. **detectorrs_cfg, pretrained='Pretrained', init_cfg='Pretrained')
  22. with pytest.raises(AssertionError):
  23. # init_cfg must be a dict
  24. DetectoRS_ResNet(
  25. **detectorrs_cfg, pretrained=None, init_cfg=['Pretrained'])
  26. with pytest.raises(KeyError):
  27. # init_cfg must contain the key `type`
  28. DetectoRS_ResNet(
  29. **detectorrs_cfg,
  30. pretrained=None,
  31. init_cfg=dict(checkpoint='Pretrained'))
  32. with pytest.raises(AssertionError):
  33. # init_cfg only support initialize pretrained model way
  34. DetectoRS_ResNet(
  35. **detectorrs_cfg, pretrained=None, init_cfg=dict(type='Trained'))
  36. with pytest.raises(TypeError):
  37. # pretrained mast be a str or None
  38. model = DetectoRS_ResNet(
  39. **detectorrs_cfg, pretrained=['Pretrained'], init_cfg=None)
  40. model.init_weights()